[SOLVED] getLoggedInUser of Google OAuth SSR gives null once logged in success
- 0
- Auth
- Web
- Cloud
![](https://cdn.discordapp.com/avatars/329603172219879424/01af7f9b2d2faf2512cd92e2df33042e.webp)
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.
![](https://cdn.discordapp.com/avatars/125334451189317632/2080f0ca10e14bea52bcdb3ae9444b32.webp)
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;
![](https://cdn.discordapp.com/avatars/329603172219879424/01af7f9b2d2faf2512cd92e2df33042e.webp)
Wahh, thank you for your help. It works like you said. need to add the cookie. Thanks a lot @Ryan
![](https://cdn.discordapp.com/avatars/329603172219879424/01af7f9b2d2faf2512cd92e2df33042e.webp)
[SOLVED] getLoggedInUser of Google OAuth SSR gives null once logged in success
![](https://cdn.discordapp.com/avatars/125334451189317632/2080f0ca10e14bea52bcdb3ae9444b32.webp)
No worries, I'll see if I can put in a PR/issue to update the repo
Recommended threads
- Telegram
I created a function to handle custom tokens. If I do the execution from the uppwrite platform everything works fine. if I make a request from postman or from t...
- How get array length withoutgetfull arra...
I need to get the number of subscribers in a group. How can I do this? The list of subscribers is obtained on the client side, and I don't want to overload it w...
- createMembership from Client, accepted p...
Hey folks, while createMembership from client the accepted parameters are ``` <TEAM_ID>', // teamId [], // roles 'email@example.com', // email (optional) '<US...
![](/images/bgs/pre-footer.png)