re-implemented JWT auth
This commit is contained in:
parent
c190d368de
commit
b47b0f3752
18 changed files with 390 additions and 174 deletions
|
|
@ -0,0 +1,32 @@
|
|||
import { IdentityContext } from '@app/server/identity';
|
||||
import { prisma } from '@app/server/prisma/client';
|
||||
|
||||
export async function LogoutResolver(
|
||||
_: any,
|
||||
__: any,
|
||||
{ req, res, identity }: IdentityContext
|
||||
): Promise<void> {
|
||||
const cookie: { jwt?: string | null } = req.cookies;
|
||||
if (cookie == null || cookie.jwt == null) return;
|
||||
|
||||
const refreshToken = cookie.jwt;
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: { refreshToken },
|
||||
select: { id: true }
|
||||
});
|
||||
|
||||
if (user == null) {
|
||||
res.clearCookie('jwt', { httpOnly: true });
|
||||
return;
|
||||
}
|
||||
|
||||
await prisma.user.update({
|
||||
where: {
|
||||
id: user.id
|
||||
},
|
||||
data: { refreshToken: null }
|
||||
});
|
||||
|
||||
res.clearCookie('jwt', { httpOnly: true });
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue