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

login at a particular route "/login" #32

Open
Raviteza7796 opened this issue Aug 4, 2020 · 5 comments
Open

login at a particular route "/login" #32

Raviteza7796 opened this issue Aug 4, 2020 · 5 comments

Comments

@Raviteza7796
Copy link

Can we change the default login at route "/" to "/login" for the application?

@thchia
Copy link
Owner

thchia commented Aug 4, 2020

Could you elaborate on this? Currently the behaviour is that whatever you have wrapped in makeAuthenticator will always redirect you to the login page if you are not logged in.

@Raviteza7796
Copy link
Author

like currently if we put out web url like www.xyz.com, it redirects to azure login but if we want for application to login only on the click of a button, how should we do it.

@Raviteza7796
Copy link
Author

now when we enter www.xyz.com, it should first redirect to welcome page where on click of a button it should perform the login step.

@AjaySewradj
Copy link

I have the exact same question, I can't figure out how to do it.

Currenly the OIDC login flow is triggered when the 'AppWithAuth' component is mounted. It will either redirect to the IdentityServer login page, or detect that the user is already logged in and give access to the protected wrapped component.
That works as advertised.

What I would like is to have a 'Login' button in my UI, which would trigger the login flow as described above.
@thchia Could you offer some guidance on how I would implement that?

@thchia
Copy link
Owner

thchia commented Aug 20, 2020

Hi @Raviteza7796 and @AjaySewradj - sorry for the late response here. To achieve what you want, I think you can do something like this:

// userManager / AppWithAuth setup removed for  brevity

<Router>
  <Switch>
    <Route
      path="/callback"
      render={routeProps => (
        <Callback
          onSuccess={user => {
            // `user.state` will reflect the state that was passed in via signinArgs.
            routeProps.history.push('/route-inside-app')
          }}
          userManager={userManager}
        />
      )}
    />
    <Route exact path="/" component={PageWithLoginButton} />
    <AppWithAuth />
  </Switch>
</Router>

Someone going to yoursite.com will land on the PageWithLoginButton component. Upon clicking the button, you can navigate them to any route defined inside the AppWithAuth (e.g. /route-inside-app). This will trigger the auth flow.

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

No branches or pull requests

3 participants