not able to get the cookies in middleware.js file in production, working fine in devlopment #64703
Unanswered
lokeshkumar0001
asked this question in
App Router
Replies: 1 comment
-
You can try to get cookies this way
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
`import { NextResponse } from "next/server";
// import { cookies } from 'next/headers'
import { BASE_URL } from "./config/config";
const protectedRoutes = ["/dashboard","/form"];
export default async function middleware(req) {
// const cookieStore = cookies();
let isAuthenticated = false;
const fetchUser = async () => {
try {
const accessToken = req.cookies.get('accessToken')?.value
};
await fetchUser();
if (!isAuthenticated) {
const absoluteURL = new URL("/auth/login", req.nextUrl.origin);
return NextResponse.redirect(absoluteURL.toString());
}
return NextResponse.next(); // Pass through the request if user is authenticated
}
export const config = {
matcher: ['/about/:path*', '/dashboard/:path*','/form/:path*'],
}
`
Can any one me with this? I am not able to read the cookies in product although it is working in development
Beta Was this translation helpful? Give feedback.
All reactions