fix return value in context

This commit is contained in:
2024-10-27 20:24:06 +07:00
parent ef89372e8c
commit 571bb93e28
5 changed files with 65 additions and 5 deletions

View File

@@ -1,4 +1,4 @@
import { Injectable, UnauthorizedException } from '@nestjs/common';
import { Injectable, Logger, UnauthorizedException } from '@nestjs/common';
import { PrismaService } from '../Prisma/prisma.service';
import { Request } from 'express';
@@ -11,18 +11,19 @@ export class GraphqlService {
async acquireContext(req: Request) {
// get x-session-id from headers
let sessionId: string;
const disableAuth = process.env.DISABLE_AUTH === 'true';
try {
sessionId = req.headers['x-session-id'] as string;
//eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (error) {
if (
process.env.NODE_ENV === 'development' &&
process.env.DISABLE_AUTH === 'true'
) {
if (disableAuth) {
return null;
}
throw new UnauthorizedException('Must provide a session ID');
}
if (disableAuth) {
return null;
}
// check if the token is valid
const session = await clerkClient.sessions.getSession(sessionId as string);
if (!session) {