Is it possible to register a user in the backend before authenticating with firebase Google sign-in?
My goal is to achieve the following steps:
- User clicks on "sign in with Google"
- User logs in with their Google account
- A popup closes, and the user sees a loading screen while a request is sent to the backend to register the user using the provided email
- If the response is successful, the user is authenticated and signed in
The issue I'm facing is that the user is immediately signed in by Firebase with a session after logging in through the popup. I am trying to delay signing in the user until the backend registration request is completed successfully.
Below is the code snippet I am currently working on:
async function GoogleSignIn() {
const result = firebase.auth().signInWithPopup(provider, { updateCurrentUser: false })
// Get the signed-in user's info
const email = result.email
const response = await fetch(`${API_URL}/api/account/register/`, {
method: "POST",
headers: {
"Content-type": "application/json",
},
body: JSON.stringify(email),
});
}