fixed 'added 'refreshToken', converted to 'httpOnly', added SSL

fixed 'gql-types' generator
This commit is contained in:
lnn0q 2025-04-06 19:57:14 +03:00
parent d179b8c7c8
commit c190d368de
20 changed files with 314 additions and 179 deletions

View file

@ -5,6 +5,8 @@ import { prisma } from './prisma/client';
import { Session } from '@generated/types';
export interface IdentityContext {
req: Request;
res: Response;
identity?: {
id: string;
username: string;
@ -19,11 +21,10 @@ export async function getIdentityContext({
res: Response;
}): Promise<IdentityContext> {
const authHeaders = req.headers.authorization;
if (authHeaders == null) return {};
if (authHeaders == null) return { req, res };
const session: Session = JSON.parse(authHeaders);
console.log(session);
const accessToken = session.accessToken;
const { accessToken } = session;
const accessTokenSecret = process.env.ACCESS_TOKEN_SECRET;
if (accessTokenSecret == null) throw new Error('No `accessToken`.');
@ -43,5 +44,14 @@ export async function getIdentityContext({
}
});
if (identity == null) throw new Error("Couldn't find the user.");
return { identity };
return { req, res, identity };
}
/* throw new GraphQLError('User is not authenticated', {
extensions: {
code: 'UNAUTHENTICATED',
http: { status: 401 }
}
}); */
// throw new GraphQLError(`${error}`);