[SOLVED] getLoggedInUser of Google OAuth SSR gives null once logged in success
- 0
- Resolved
- Auth
- Web
- Cloud
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
- GB Hours IS NOT resetting
Hi, I was checking my usage and noticed that all of my usage quotas were reset on August 20, 2026, when my billing cycle renewed. Everything else appears to ha...
- Confused about Appwrite Pro pricing
Hi. I've been subscribed to the $25 Appwrite Pro plan, but I've been getting charged $40. I have two projects on my account. I was wondering where exactly the e...
- How can I disable client-side account re...
Hi everyone! I’m currently building a game backend using Appwrite, and I’d like to prevent users from creating new accounts directly through the client. My go...