optimize context
This commit is contained in:
@@ -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;
|
||||
},
|
||||
}),
|
||||
|
||||
|
||||
Reference in New Issue
Block a user