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

authenticateHandler.handle returning null causes error #737

Open
cancan101 opened this issue Jun 20, 2022 · 2 comments
Open

authenticateHandler.handle returning null causes error #737

cancan101 opened this issue Jun 20, 2022 · 2 comments

Comments

@cancan101
Copy link

The docs for authenticateHandler say:

If there is no associated user (i.e. the user is not logged in) a falsy value should be returned.

However if I return null I then get the following Error:

if (!user) {
throw new ServerError('Server error: `handle()` did not return a `user` object');
}

@cancan101
Copy link
Author

and perhaps related is there anyway to redirect a non logged in user from within authenticateHandler to a login screen?

@tswaters
Copy link

tswaters commented Oct 12, 2022

Noticed this as well. We use the authenticateHandler for the login form that shows up on the authorization server, for auth code flow.... something like this:

app.post('/login', async handler(req, res) {
  await req.oauth.authorize({
    authenticateHandler: {
      async handle() {
        return app.oauth.getUser(req.body.username, req.body.password, req.query)
      },
    },
  })
})

Before, the modal method would return null if a valid user could not be found and we'd get a server error. Now, it throws an invalid grant error if a user can't be found, similar to how it gets handled in the password flow, here:

if (!user) {
throw new InvalidGrantError('Invalid grant: user credentials are invalid');
}

So this way it's at least consistent between the two.... IMO, the code in the authorize handler should throw an InvalidGrantError similar to how the password grant type does it, see above ^^

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

2 participants