
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
- phantom relationships appear on parent c...
i have this bug were my past deleted collection apears as relationship to my parent collection. when i try to delete that relationship from parent it gives me e...
- Attributes Problem - Cloud
I am not able to see the attribute columns and their context on cloud. Can you help?
- Authorization header not working in Appw...
I have an Appwrite function that takes a custom bearer token as authentication. The function works fine locally when I test it with `appwrite run functions`, bu...
