fixed server issue on document
This commit was merged in pull request #8.
This commit is contained in:
+8
-4
@@ -9,21 +9,25 @@ const checkAuthentication = async () => {
|
||||
};
|
||||
|
||||
const isTokenValid = () => {
|
||||
if (typeof window === "undefined") {
|
||||
return false; // Don't execute this code on the server-side
|
||||
}
|
||||
|
||||
const cookies = document.cookie.split("; "); // Get all cookies and split them into an array
|
||||
|
||||
for (const cookie of cookies) {
|
||||
const [name, value] = cookie.split("="); // Split the cookie into its name and value
|
||||
|
||||
if (name === "cmc-token" && value) {
|
||||
if (name.trim() === "cmc-token" && value) {
|
||||
return true; // The cmc-token cookie exists
|
||||
}
|
||||
}
|
||||
|
||||
return false; // The cmc-token cookie does not exist
|
||||
return false;
|
||||
};
|
||||
|
||||
export async function middleware(req) {
|
||||
const token = isTokenValid()
|
||||
const token = isTokenValid();
|
||||
// req.cookies["cmc-token"]; // Access the token from cookies
|
||||
const cookieList = cookies();
|
||||
|
||||
@@ -50,7 +54,7 @@ export async function middleware(req) {
|
||||
// Add authentication logic here (verify the token, etc.)
|
||||
// const isAuthenticated = verifyToken(token);
|
||||
const isAuthenticated = cookieList.has("cmc-token");
|
||||
console.log(token)
|
||||
console.log(token);
|
||||
|
||||
if (!isAuthenticated) {
|
||||
// Handle unauthenticated users
|
||||
|
||||
Reference in New Issue
Block a user