Return GraphQL auth errors for manager requests
Build and deploy Docker image / build (push) Successful in 2m14s

This commit is contained in:
Ruslan Bakiev
2026-06-03 17:13:19 +07:00
parent 3ecf082643
commit 5dd28d388f
2 changed files with 13 additions and 20 deletions
+10 -1
View File
@@ -32,6 +32,14 @@ function getBearerToken(req: FastifyRequest): string {
return token;
}
function optionalBearerToken(req: FastifyRequest): string | null {
const auth = req.headers.authorization || "";
if (!auth.startsWith("Bearer ")) return null;
const token = auth.slice(7);
if (!token || token === "undefined") return null;
return token;
}
function scopesFromPayload(payload: JWTPayload): string[] {
const scope = payload.scope;
if (!scope) return [];
@@ -98,7 +106,8 @@ export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
export async function managerContext(
req: FastifyRequest,
): Promise<AuthContext> {
const token = getBearerToken(req);
const token = optionalBearerToken(req);
if (token === null) return { scopes: [] };
const { payload } = await jwtVerify(token, jwks, {
issuer: LOGTO_ISSUER,
audience: LOGTO_ORDERS_AUDIENCE,