finalized adding support for access tokens
This commit is contained in:
+8
-14
@@ -1,8 +1,8 @@
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import { getToken } from "next-auth/jwt";
|
||||
import { prisma } from "./db";
|
||||
import { User } from "@prisma/client";
|
||||
import verifySubscription from "./verifySubscription";
|
||||
import verifyToken from "./verifyToken";
|
||||
|
||||
type Props = {
|
||||
req: NextApiRequest;
|
||||
@@ -15,21 +15,15 @@ export default async function verifyUser({
|
||||
req,
|
||||
res,
|
||||
}: Props): Promise<User | null> {
|
||||
const token = await getToken({ req });
|
||||
const token = await verifyToken({ req });
|
||||
|
||||
if (typeof token === "string") {
|
||||
res.status(401).json({ response: token });
|
||||
return null;
|
||||
}
|
||||
|
||||
const userId = token?.id;
|
||||
|
||||
if (!userId) {
|
||||
res.status(401).json({ response: "You must be logged in." });
|
||||
return null;
|
||||
}
|
||||
|
||||
if (token.exp < Date.now() / 1000) {
|
||||
res
|
||||
.status(401)
|
||||
.json({ response: "Your session has expired, please log in again." });
|
||||
return null;
|
||||
}
|
||||
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: userId,
|
||||
|
||||
Reference in New Issue
Block a user