add team invitation functionality [WIP]

This commit is contained in:
daniel31x13
2024-10-21 13:59:05 -04:00
parent d146ec296c
commit cffc74caa4
32 changed files with 1083 additions and 98 deletions
+47
View File
@@ -0,0 +1,47 @@
import { NextApiRequest } from "next";
import { getToken } from "next-auth/jwt";
import { prisma } from "./db";
type Props = {
req: NextApiRequest;
};
export default async function isAuthenticatedRequest({ req }: Props) {
const token = await getToken({ req });
const userId = token?.id;
if (!userId) {
return null;
}
if (token.exp < Date.now() / 1000) {
return null;
}
// check if token is revoked
const revoked = await prisma.accessToken.findFirst({
where: {
token: token.jti,
revoked: true,
},
});
if (revoked) {
return null;
}
const findUser = await prisma.user.findFirst({
where: {
id: userId,
},
include: {
subscriptions: true,
},
});
if (findUser && !findUser?.subscriptions) {
return null;
}
return findUser;
}