firebase / firebase-js-sdk

Firebase Javascript SDK
https://firebase.google.com/docs/web/setup
Other
4.84k stars 889 forks source link

[React] Login with signInWithRedirect does not work with option 4 #8598

Open sumitsahoo opened 2 hours ago

sumitsahoo commented 2 hours ago

Operating System

macOS 15.0.1

Environment (if applicable)

Chrome 130, Edge 130, Firefox,

Firebase SDK Version

10.14.1 & 11.0.1

Firebase SDK Product(s)

Auth

Project Tooling

React app with webpack

Detailed Problem Description

As per the Firebase documentation on self hosted helper files for signInWithRedirect, we have added the files to proper directories i.e. /__/auth/ and /__/firebase/ as seen below. We have added to the public directory as a build process is involved for the React app.

Screenshot 2024-10-25 at 3 21 34 PM

For the deployed version to work and fix files being downloaded without being processed we have to update nginx config.

Screenshot 2024-10-25 at 3 24 33 PM

But it never works, the redirect does happen but the result inside getRedirectResult is always null

// Handle redirect and get user details
    const getUserDetails = async () => {
      try {
        const userCred = await getRedirectResult(auth);
        console.log("userCred", userCred);
      }
      catch (error) {
        console.log("error", error);
      }
    };

To test it locally we used mkcert to enable HTTPS but still, the result was the same. Steps to enable HTTPS are below:

  1. Install mkcert
    npm install -g mkcert
  2. Create CA
mkcert create-ca
  1. Create Cert
mkcert create-cert
  1. Install the certificate and trust it in the system (macOS & Windows)
  2. Update the run script in package.json
HTTPS=true SSL_CRT_FILE=cert.crt SSL_KEY_FILE=cert.key react-scripts start

To make the redirect work, we had to rename handler to handler.html and iframe to iframe.html. However, there are no clear instructions on how to test this login locally from Firebase, which I find disappointing.

With these also the result is the same. This is such a big issue and I want to know why there is no traction on this from Firebase. This is a dealbreaker for the Enterprise use case. Related issue: #8329

Steps and code to reproduce issue

Below is the code for initiating the signInWithRedirect

const auth = getAuth(app);
const result = await signInWithRedirect(auth, provider);

And in App.js we are observing the redirect response

// Handle redirect and get user details
    const getUserDetails = async () => {
      try {
        const userCred = await getRedirectResult(auth);
        console.log("userCred", userCred);
      }
      catch (error) {
        console.log("error", error);
      }
    };

The result is always null.

google-oss-bot commented 2 hours ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.