
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
- what is the best way to redirect a prett...
I tried to do this in a function, but after redirecting to the bucket and try to play video, i get CORS error: The 'Access-Control-Allow-Origin' header has a va...
- pricing changes feedback & question
Hi Appwrite team I don't have any issues with the changes in pricing....except I was hoping the change would involve something that is an actual problem for me...
- why the createOAuth2Token method does no...
I need it to get secret and key, how to get in flutter code?
