From 425e81448b32f3954902d57a29811898a554f604 Mon Sep 17 00:00:00 2001 From: Kevin-Umali Date: Sat, 21 Oct 2023 15:10:28 +0800 Subject: [PATCH 1/2] Fix cookies v1 --- .../src/controllers/authentication.controller.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/src/controllers/authentication.controller.ts b/server/src/controllers/authentication.controller.ts index 430d0b9..7aec000 100644 --- a/server/src/controllers/authentication.controller.ts +++ b/server/src/controllers/authentication.controller.ts @@ -25,6 +25,11 @@ export const authorizeUser = async (req: BodyRequest, res: Response return; } + if (user.banned) { + sendError(res, "User is banned.", 401); + return; + } + const { accessToken, refreshToken } = generateTokens(user.id, user.username); await prisma.refreshToken.create({ @@ -131,7 +136,7 @@ export const refreshToken = async (req: Request, res: Response, next: NextFuncti res.cookie("refreshToken", refreshTokenInDb.token, { secure: process.env.NODE_ENV === "production", httpOnly: true, - sameSite: "lax", + sameSite: "none", path: "/", expires: refreshTokenInDb.expiresAt, }); @@ -156,9 +161,11 @@ export const logoutUser = async (req: Request, res: Response, next: NextFunction const prisma = req.app.get("prisma") as PrismaClient; - await prisma.refreshToken.delete({ - where: { token: refreshToken }, - }); + if (refreshToken) { + await prisma.refreshToken.delete({ + where: { token: refreshToken }, + }); + } res.clearCookie("refreshToken"); From 8ffc01bd09ca4ab644f27598cf5e8e10412f1b0a Mon Sep 17 00:00:00 2001 From: Kevin-Umali Date: Sat, 21 Oct 2023 15:17:44 +0800 Subject: [PATCH 2/2] Fix cookies v2 --- client/app/login/loading.tsx | 5 +++++ server/src/controllers/authentication.controller.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) create mode 100644 client/app/login/loading.tsx diff --git a/client/app/login/loading.tsx b/client/app/login/loading.tsx new file mode 100644 index 0000000..c74630a --- /dev/null +++ b/client/app/login/loading.tsx @@ -0,0 +1,5 @@ +import PageLoader from "@/components/page-loader"; + +export default function Loading() { + return ; +} diff --git a/server/src/controllers/authentication.controller.ts b/server/src/controllers/authentication.controller.ts index 7aec000..58bc2b1 100644 --- a/server/src/controllers/authentication.controller.ts +++ b/server/src/controllers/authentication.controller.ts @@ -55,7 +55,7 @@ export const authorizeUser = async (req: BodyRequest, res: Response secure: process.env.NODE_ENV === "production", httpOnly: true, signed: true, - sameSite: "lax", + sameSite: "none", expires: refreshTokenExpiry, });