I'm really sure there is bug. Step to reproduce:
- download this project https://github.com/appwrite/demos-for-react/tree/master/nextjs/server-side-rendering
- Change OAuth sign in, from Github with Google
"use server";
import { createAdminClient } from "./appwrite";
import { headers } from "next/headers";
import { redirect } from "next/navigation";
import { OAuthProvider } from "node-appwrite";
export async function signInWithGoogle() {
const { account } = await createAdminClient();
const origin = headers().get("origin");
const successUrl = `${origin}/oauth`;
const failureUrl = `${origin}/signin`;
const redirectUrl = await account.createOAuth2Token(
OAuthProvider.Google,
successUrl,
failureUrl
);
redirect(redirectUrl);
}
- npm run dev
- Sign in with google
- You will redirect to sign in page because of below lines. Means, getLoggedInUser is null.
// app/account/page.tsx
const user = await getLoggedInUser();
if (!user) redirect("/signin");
- Refresh the page, then you will be redirected to /account page.
Maybe there is some delay, with the session, i'm not sure, but I have checked my local browser, and session in Appwrite console exist.
I think I ran into a similar problem the other day. It's how Next handles redirects from what I can tell. The way I fixed it was by adding the cookie to the NextResponse as well at the end before returning it in /app/oauth/route.ts
const response = NextResponse.redirect(`${request.nextUrl.origin}/account`);
response.cookies.set(SESSION_COOKIE, session.secret);
return response;
Wahh, thank you for your help. It works like you said. need to add the cookie. Thanks a lot @Ryan
[SOLVED] getLoggedInUser of Google OAuth SSR gives null once logged in success
No worries, I'll see if I can put in a PR/issue to update the repo
Recommended threads
- RowList: The value of total is coming as...
RowList: The value of total is coming as a String, so it throws an error because it’s not parsed into an int. Error: TypeError: \"37\": type 'String' is not a ...
- Docker Compose MongoDB Setup
everythings work fine but the mongodb fails on startup everytime. log: ``` Generating random MongoDB keyfile... /bin/bash: line 9: : No such file or directory ...
- Auth broken after update from 1.8.0 to 1...
So ive been having issues creating, deleting or updating users on my appwrite instance after i updated from 1.8.0 to version 1.9.0. When trying to create a user...