Back

NextJS OAuth Inconsistent Redirect Results

  • 0
  • Self Hosted
  • Auth
  • Web
Dauntless
12 Mar, 2024, 19:33

I have just implemented the SSR authentication flow for Next.js.

I have two providers, GitHub and Discord.

With GitHub everything works flawlessly. The user is logged in already on redirect.

With Discord, however, the user object returned from this function is null.

TypeScript
export const getLoggedInUser = cache(async () => {
  try {
    const { account } = await createSessionClient();
    return await account.get();
  } catch (error) {
    return null;
  }
});

I have to refresh the page, and then the user object is retrieved and the user is logged in.

I've looked at the HTTP Request objects in dev tools, and most apparent difference are the referrer policies. The redirect urls from GitHub are origin-when-cross-origin while the ones from Discord are strict-origin-when-cross-origin.

I have only tested this in a local development environment.

TL;DR
Implemented SSR auth flow in Next.js; GitHub login works, Discord login returns null user object. Need to refresh page for user object to be retrieved. Discord redirect urls have 'strict-origin-when-cross-origin' referrer policy. Only tested in local env.
Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more