optimize context

This commit is contained in:
2024-10-29 01:54:19 +07:00
parent 34cea2ccd3
commit ba54d3466c
7 changed files with 11 additions and 77 deletions

View File

@@ -130,23 +130,7 @@ export class UserSchema extends PothosSchema {
description: 'Retrieve the current user by token.',
type: this.user(),
resolve: async (query, root, args, ctx) => {
// get session id from X-Session-Id
const sessionId = ctx.req.headers['x-session-id'];
if (!sessionId)
throw new UnauthorizedException({
message: 'No session ID found',
});
// verify the token
const session = await clerkClient.sessions.getSession(
sessionId as string,
);
if (!session) throw new UnauthorizedException();
const user = await this.prisma.user.findUnique({
where: { id: session.userId },
});
if (!user) throw new UnauthorizedException();
ctx.me = user;
return user;
return ctx.me;
},
}),