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
- No server error on selfhosted appwrite
Please help me, my clients is ask what happen on their data? How can i make it up again?
- Upgrading selfhost version?
It is okay to upgrade version to higher one, of my current version is 1.7.4 to 1.8.1. Is that safe to do cause my clients already have data on that? Also is a...
- Local Serverless Function Testing: Are D...
I have followed the instructions to get the CLI working, and have been able to log-in, initialize my project, and created a simple Python function, which calls ...