mccordryan / firebaseui-react

FirebaseUI rebuilt as a fully functional and customizable React component.
https://fuidemo.vercel.app
15 stars 6 forks source link

Attempts to register existing email #30

Open ybwai opened 7 months ago

ybwai commented 7 months ago

Hey, on a brand new nextjs app, trying to get this library working, but I have to issues:

  1. When using an existing email it attempts to re-register me resulting in a 400 EMAIL_EXISTS
  2. Using a new email it does not redirect to the continueUrl

I only have three files, a firebase init, and empty homepage and a Login page with your component

// nextjs/firebase/index.ts
const app = initializeApp(firebaseConfig);
export const auth = getAuth(app);
export const firebaseuiConfig = {
  continueUrl: "/",
  signInOptions: ["emailpassword", "google.com"],
};

// nextjs/app/login/page.ts
"use client";

import { auth, firebaseuiConfig } from "@/firebase";
import FirebaseUIReact from "firebaseui-react";

export default function Login() {
  return (
    <>
      <h1>Log In</h1>
      <FirebaseUIReact auth={auth} config={firebaseuiConfig} />
    </>
  );
}
mccordryan commented 7 months ago

Hey, I'll try and recreate this later today. It should log you in again since you haven't set an authType in your config. In the meantime, I would try manually setting authType: "both" in your configuration and seeing if that resolves it? But I'll take a look regardless.

The continueUrl field isn't for routing/redirecting the user through the component. This is the base url that gets passed along to password reset emails (and email link sign ins), and should usually be set to whatever page you have the <FirebaseUIReact> component on.

For routing the user after they've signed in, you can use the signInSuccessWithAuthResult callback function:

import {useRouter} from "next/navigation";

const router = useRouter();

const firebaseuiConfig = {
    signInOptions: ["emailpassword", "google.com"],
    callbacks: {
        signInSuccessWithAuthResult: () => router.push("/yourRedirectTarget");
    }
}