From d0a4ff691ea5097022245f5326e8e3a3636cbf09 Mon Sep 17 00:00:00 2001 From: sianida26 Date: Fri, 1 Mar 2024 17:15:09 +0700 Subject: [PATCH] Add check user from header and cookie --- src/modules/auth/utils/getCurrentUser.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/modules/auth/utils/getCurrentUser.ts b/src/modules/auth/utils/getCurrentUser.ts index 2d3d279..1787e02 100644 --- a/src/modules/auth/utils/getCurrentUser.ts +++ b/src/modules/auth/utils/getCurrentUser.ts @@ -1,7 +1,8 @@ import { cache } from "react" import "server-only" import getUserFromToken from "./getUserFromToken" -import { cookies } from "next/headers" +import { cookies, headers } from "next/headers" +import getTokenFromHeaders from "./getTokenFromHeaders" /** * Retrieves the current user based on the JWT token stored in cookies. @@ -13,7 +14,7 @@ import { cookies } from "next/headers" */ const getCurrentUser = async () => { // Retrieve the token from cookies - const token = cookies().get("token")?.value; + const token = cookies().get("token")?.value ?? getTokenFromHeaders(headers()); // If no token is found, return null (no current user) if(!token) return null;