re-implemented JWT auth

This commit is contained in:
lnn0q 2025-04-18 14:47:42 +03:00
parent c190d368de
commit b47b0f3752
18 changed files with 390 additions and 174 deletions

View file

@ -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 });
}