
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
- 500 Error on Console when Using Custom D...
Hey 👋 I’ve set up a custom domain for my Appwrite Cloud project (<my-custom-domain>). DNS is configured and the organization view loads fine when I open the c...
- 2 Columns still processing since yesterd...
Hey o/ Yesterday (around <t:1758045600:f>), I created a database and added several columns to it. After about 15 minutes, most of the "processing" tags disappe...
- 503 Timeout when Updating or Upserting D...
Hey I’m running into an issue when trying to update or upsert a row in Appwrite. The request hangs for a while and then throws this error: ``` AppwriteException...
