Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

loginWithPopup close doesn't return any error response #821

Open
6 tasks done
JeremyLiang0105 opened this issue Jan 13, 2025 · 4 comments
Open
6 tasks done

loginWithPopup close doesn't return any error response #821

JeremyLiang0105 opened this issue Jan 13, 2025 · 4 comments
Labels
bug Something isn't working

Comments

@JeremyLiang0105
Copy link

JeremyLiang0105 commented Jan 13, 2025

Checklist

Description

We are using loginwithpopup (Auth0's sdk link) to open the Auth0's universal login MFA enrollment prompt in a popup window. The issue we are encountering is we cannot find a way to handle if the user closes/cancels the popup page. The expected behavior is that when the user closes the popup, it should return us an error to indicate it so we could catch it and display an error on our app to instruct the user to click the button to open the popup again. We've tried the solutions from auth0/auth0-spa-js#599 but it doesn't work because we don't receive any error response. The happy path works fine
This is the code we use

import { useAuth0 } from '@auth0/auth0-react';
 const { loginWithPopup } = useAuth0();
 try {
   await loginWithPopup({
     audience: `https://${getWebsocketBaseUrl()}/api`,
     enroll_mfa: true,
    });
 } catch (e) {
      console.debug('Popup was closed before login completed');
 }

No error is being thrown when the user closes the popup without completing the steps.

The version of auth0-react we are using is "@auth0/auth0-react": "1.12.1"

Reproduction

Code snippet copied above.

Additional context

No response

auth0-react version

1.12.1

React version

18

Which browsers have you tested in?

Chrome

@JeremyLiang0105 JeremyLiang0105 added the bug Something isn't working label Jan 13, 2025
@JeremyLiang0105
Copy link
Author

Got redirected here from the issue I raised in auth0-spa-js repo: auth0/auth0-spa-js#1334

@JeremyLiang0105 JeremyLiang0105 changed the title loginWithPopup closedoesn't return any error response loginWithPopup close doesn't return any error response Jan 13, 2025
@JeremyLiang0105
Copy link
Author

@saadman13

@saadman13
Copy link

Same behavior on Firefox too.

@nicosabena
Copy link

nicosabena commented Jan 13, 2025

Hey @JeremyLiang0105
The paradigm with auth0-react is different than the one in auth0-spa-js.
useAuth0().loginWithPopup won't throw an error if it fails. Instead, it will update the error state (obtained from useAuth0().error), so that your components can react to it.

A crude example:

const myComponent = () => {
  const { error, isLoading, isAuthenticated } = useAuth0();
  
  if (error) {
    return <div>There was an error while authenticating: {error}</div>;
  }
  // ...
}

See https://github.com/auth0/auth0-react/blob/main/examples/cra-react-router/src/App.tsx for another example.

See here how the error from auth0-spa-js is caught and transformed into a state update via a dispatch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants