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

Auth provider login Promise rejection with "message" doesn't trigger notification message #9754

Closed
olesmarola opened this issue Apr 3, 2024 · 2 comments

Comments

@olesmarola
Copy link

olesmarola commented Apr 3, 2024

What you were expecting:
Notification triggers when login func returns Promise.reject({message: 'Error notification'});
What happened instead:
I got only an error message in the console.
Steps to reproduce:

  1. Go to authProvider;
  2. return Promise.reject({message: 'Error notification'}) in "login" func.
    Related code:
login: async (params: LoginParams) => {
    const request = new Request(`/auth/login`, {
      method: 'POST',
      body: JSON.stringify(
            {
              username: params.username,
              password: params.password,
            },
      ),
      headers: new Headers({ 'Content-Type': 'application/json' }),
    });

    try {
      const response = await fetch(request);

      if (response.status < 200 || response.status >= 300) {
        return Promise.reject({ message: 'Invalid credentials' });
      }

      const authResponse = await response.json();

      if (!authResponse.accessToken) {
        return Promise.reject({
          message: 'Your account is not active yet. Please contact some of the admins to take access.',
        });
      }

      cookies.set('AccessToken', authResponse.accessToken);
    } catch (e) {
      return Promise.reject({ message: 'Something went wrong. Please, try again.' });
    }
}

Other information:
https://marmelab.com/react-admin/doc/3.19/Authentication.html#:~:text=string%20%7C%20%7B%20message%3F%3A%20string%20%7D%20error%20message%20to%20display

Environment

  • React-admin version: 4.16.12
  • Last version that did not exhibit the issue (if applicable): -
  • React version: 18.2.0
  • Browser: latest chrome
@erwanMarmelab
Copy link
Contributor

Hi @olesmarola. I can't reproduce this in our demo. Would you mind building adding a repro to this issue?

@fzaninotto
Copy link
Member

No news for some time, closing.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants