Add check user from header and cookie
This commit is contained in:
parent
a794342480
commit
d0a4ff691e
|
|
@ -1,7 +1,8 @@
|
||||||
import { cache } from "react"
|
import { cache } from "react"
|
||||||
import "server-only"
|
import "server-only"
|
||||||
import getUserFromToken from "./getUserFromToken"
|
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.
|
* Retrieves the current user based on the JWT token stored in cookies.
|
||||||
|
|
@ -13,7 +14,7 @@ import { cookies } from "next/headers"
|
||||||
*/
|
*/
|
||||||
const getCurrentUser = async () => {
|
const getCurrentUser = async () => {
|
||||||
// Retrieve the token from cookies
|
// 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 no token is found, return null (no current user)
|
||||||
if(!token) return null;
|
if(!token) return null;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user