Use Fastify Mercurius and GraphQL contracts
Build Docker Image / build (push) Has been cancelled

This commit is contained in:
Ruslan Bakiev
2026-06-01 00:25:27 +05:00
parent e5cbb8855d
commit 7eb1742d6a
6 changed files with 1252 additions and 1614 deletions
+7 -5
View File
@@ -1,6 +1,6 @@
import { createRemoteJWKSet, jwtVerify, type JWTPayload } from "jose";
import { GraphQLError } from "graphql";
import type { Request } from "express";
import type { FastifyRequest } from "fastify";
const LOGTO_JWKS_URL =
process.env.LOGTO_JWKS_URL || "https://auth.optovia.ru/oidc/jwks";
@@ -16,7 +16,7 @@ export interface AuthContext {
scopes: string[];
}
function getBearerToken(req: Request): string {
function getBearerToken(req: FastifyRequest): string {
const auth = req.headers.authorization || "";
if (!auth.startsWith("Bearer ")) {
throw new GraphQLError("Missing Bearer token", {
@@ -61,7 +61,7 @@ export async function publicContext(): Promise<AuthContext> {
return { scopes: [] };
}
export async function userContext(req: Request): Promise<AuthContext> {
export async function userContext(req: FastifyRequest): Promise<AuthContext> {
const token = getBearerToken(req);
const { payload } = await jwtVerify(token, jwks, { issuer: LOGTO_ISSUER });
return {
@@ -70,7 +70,7 @@ export async function userContext(req: Request): Promise<AuthContext> {
};
}
export async function teamContext(req: Request): Promise<AuthContext> {
export async function teamContext(req: FastifyRequest): Promise<AuthContext> {
const token = getBearerToken(req);
const { payload } = await jwtVerify(token, jwks, {
issuer: LOGTO_ISSUER,
@@ -95,7 +95,9 @@ export async function teamContext(req: Request): Promise<AuthContext> {
};
}
export async function managerContext(req: Request): Promise<AuthContext> {
export async function managerContext(
req: FastifyRequest,
): Promise<AuthContext> {
const token = getBearerToken(req);
const { payload } = await jwtVerify(token, jwks, {
issuer: LOGTO_ISSUER,