Skip to content

After login, what callback scenarios should I use to create a new user in the backend using the ID token? #12036

Answered by ozooxo
ozooxo asked this question in Help
Discussion options

You must be logged in to vote

I found out a solution here.

So I redirect signIn to a new /welcome page.

import { signIn } from "@/auth";

await signIn(... { redirectTo: "/welcome" });

I define an idempotent createUserFromIdToken() which call the backend API to create the user, and do nothing if the user already exists.

Then in the welcome page, I do a

import { redirect } from "next/navigation"; 

export default async function Welcome() {
  await createUserFromIdToken();
  redirect("/dashboard");
}

to the real login landing page (/dashboard in this case).

This solves the problem.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ozooxo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
1 participant