Next-Auth redirection to auth/login inside of dashboard
Unanswered
Black carp posted this in #help-forum
Black carpOP
Hello all,
I don't know why, but every time I validate my login with a magic link, I get this behavior:
I have a problem with the session. I've tried with middleware and without it, but I still have the same problem. Do you have a solution, please?
I don't know why, but every time I validate my login with a magic link, I get this behavior:
GET /api/auth/session 200 in 105ms
Compiling /dashboard ...
✓ Compiled /dashboard in 876ms (735 modules)
GET /dashboard 200 in 1040ms
GET /auth/login 200 in 38msI have a problem with the session. I've tried with middleware and without it, but I still have the same problem. Do you have a solution, please?
3 Replies
Siamese Crocodile
Hello, sir. I think you should follow this guide.
1. Ensure that the session is properly initialized and persisted by checking the session cookie and using getSession() to verify the user's login status.
2. Confirm that your /api/auth/session endpoint returns valid session data and that the session is correctly handled on each page, including redirects.
My two cents.
1. Ensure that the session is properly initialized and persisted by checking the session cookie and using getSession() to verify the user's login status.
2. Confirm that your /api/auth/session endpoint returns valid session data and that the session is correctly handled on each page, including redirects.
My two cents.
Black carpOP
I check this thank you
Black carpOP
src\app\api\auth[...nextauth]\route.ts
I'm on local : localhost:4000 i don't know if the config here it's correct or no ?
session: {
strategy: "database", // Consider switching to database strategy in production
maxAge: 7 * 24 * 60 * 60, // 1 week maxAge (adjust as needed)
},
cookies: {
sessionToken: {
name: "next-auth.session-token", // Nom du cookie
options: {
httpOnly: true, // Empêche l'accès côté client
sameSite: process.env.NODE_ENV === "production" ? "lax" : "strict", // Strict en local pour éviter les erreurs
secure: process.env.NODE_ENV === "production",
path: "/", // Disponible sur tout le site
maxAge: 7 * 24 * 60 * 60
},
},I'm on local : localhost:4000 i don't know if the config here it's correct or no ?