
can someone tell, after i use google login in server side i set the cookie and return the redirect response but in my middleware session is still undefined and it re redirects to /login and when i refresh the page the session is available in middleware how can i fix that ?
my middleware code for redirecting
const user = await getLoggedInUser()
const isLoginPage = req.nextUrl.pathname === "/login"
const isRegisterPage = req.nextUrl.pathname === "/register"
if (!user && !isLoginPage && !isRegisterPage) {
const url = req.nextUrl.clone()
url.pathname = "/login"
return NextResponse.redirect(url)
}
my /api/oauth which is success url for account.createOAuth2Token()
cookies().set(SESSION_COOKIE, session.secret, {
path: "/",
httpOnly: true,
sameSite: "strict",
secure: true,
});
const res = NextResponse.redirect("http://localhost:3000/home")
return res;
getLoggedInUser()
export async function getLoggedInUser() {
try {
const { account } = await createSessionClient()
const user = await account.get()
return user;
} catch (err) {
return null;
}
}
Recommended threads
- [BUG] Next.js 16 is broken on appwrite.
The latest version of Next.js fails to build on appwrite and shows the error: `Adapter mismatch. Detected: static does not match with the set adapter: ssr` whil...
- 500 Internal Server Error
This error shows 500 on live site, but it works perfectly on Localhost.
- Multiple Set-Cookie headers collapsed on...
I’m deploying a Next.js 15 app to Appwrite → Deploy → Sites. In app/api/auth/login/route.ts I try to set 3 cookies. Variant A (manual headers): const headers ...
