♻️ refactor: app token and oAuth endpoint request

These changes include:
1. Replacing the app token with a standard authorization barrier.
2. Changing the response body in the OAuth request by wrapping the endpoint link with a structure instead of placing it in the callback payload data.
This commit is contained in:
2026-01-07 23:56:44 +07:00
parent d3fcf281b3
commit d8e8ec3fa7
4 changed files with 23 additions and 18 deletions

View File

@ -3,10 +3,14 @@ import { returnErrorResponse } from "../../helpers/callback/httpResponse";
export const appAccessTokenMiddleware = () =>
new Elysia().onRequest(({ request, set }) => {
const headerToken = request.headers.get("access_token");
const storedToken = process.env.API_KEY;
const headerToken = request.headers.get("authorization");
if (!headerToken) return returnErrorResponse(set, 401, "Unauthorized");
if (headerToken !== storedToken) {
return returnErrorResponse(set, 403, "Unauthorized");
}
const storedToken = process.env.API_KEY;
const [scheme, token] = headerToken.split(" ");
if (scheme !== "Bearer" || !token)
return returnErrorResponse(set, 401, "Invalid auth format");
if (token !== storedToken)
return returnErrorResponse(set, 403, "Forbidden");
});