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
- Deploy function not working - 503
Hellon i get this error message, when i try to deploy a new version of a function <html><body><h1>503 Service Unavailable</h1>No server is available to handle...
- Error When load the website
Hi, I am getting this error whenever I reload my website please help me, I am using react Error: ** GET https://cloud.appwrite.io/v1/account 401 (Unauthoriz...
- Migrate from cloud to localhost
Hello everyone. I need to migrate my test project from cloud to localhost, however it seems that this is possible only if a self-hosted appwrite instance it's h...