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

Authorization on request #4

Open
igvnv opened this issue Dec 3, 2020 · 2 comments
Open

Authorization on request #4

igvnv opened this issue Dec 3, 2020 · 2 comments
Labels
enhancement New feature or request

Comments

@igvnv
Copy link

igvnv commented Dec 3, 2020

Hi Luke! Thank you for your solution.

I faced a problem that using <AuthProvider /> forces application to auth, but in some cases I need to display a welcome page for unauthorized users.

Is it possible to get auth state outside of AuthProvider and start authentication process on user action (e.g. click on login button)?

Or have forceLogin property similar to react-aad-msal package. Something like:

import { AuthProvider, AuthProviderState, login } from './authentication/Msal';

ReactDOM.render(
  <AuthProvider forceLogin={false} render={({ state }) => {
    switch (state) {
      case AuthProviderState.Unauthenticated:
        return <button onClick={login}>Login</button>;
      case AuthProviderState.Success:
        return <App />;
    }
  }} />
);
@lukezirngibl lukezirngibl added the enhancement New feature or request label Dec 4, 2020
@lukezirngibl
Copy link
Owner

lukezirngibl commented Dec 4, 2020

Hey @igvnv, couldn't you have the login button at route /login and the authenticated app at route /app, and just have the login button link to the /app route?

@igvnv
Copy link
Author

igvnv commented Dec 4, 2020

On main page (/) I need to check if user is authorized. I could use the useAccount hook, but it doesn't work outside of AuthProvider. If I wrap main page in AuthProvider, it will lead to force login.

My app is for authenticated users only but it is a good UX practice to show to users what app are they going to use. Silent redirect can lead to misunderstanding.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants