Next-auth: Add option to pass callbackUrl to client on signin/signout

Created on 5 Jun 2020  路  4Comments  路  Source: nextauthjs/next-auth

When calling signin() / signout() methods from client side, the callback url is hardcoded to window.location.

It would be great if we could define a custom callback url to redirect the user to another route once signed in/out.

Usecases:

  • Redirect an user to his profile page once signed in.
  • Redirect an user to a specific page after clicking on a sign out button.

Currently the signin() method allows us to pass a provider id, maybe we could also pass an optional parameter like { callbackUrl }?

enhancement

Most helpful comment

What if I'm using the signin method from next-auth/client?

This issue is actually about adding support for just that.

The client methods don't support callbackUrl as an option yet, but it's a simple and reasonable request and one that will probably come quite soon.

All 4 comments

Thanks for thinking this through. Being able to specify the callbackURL like that as an option to both signin() and signout() sounds like the perfect way to support this!

I'm not 100% sure if signout supports callback URL, but if it doesn't, it should.

+1 good idea we should do this

PS: You can currently provide callbackUrl as a query param to sign in pages:

e.g.

  • /api/auth/signin?callbackUrl=/some/url
  • /api/auth/signin/google?callbackUrl=/some/url
  • /api/auth/signin/email?callbackUrl=/some/url

(etc)

You probably know this, but fully agree it should be possible to do it from the signin() function too - the point of it is supposed to be to make things easier.

I am not 100% sure about sign out flow without checking (but it is supposed to work that way).

What if I'm using the signin method from next-auth/client?

What if I'm using the signin method from next-auth/client?

This issue is actually about adding support for just that.

The client methods don't support callbackUrl as an option yet, but it's a simple and reasonable request and one that will probably come quite soon.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

loonskai picture loonskai  路  3Comments

eatrocks picture eatrocks  路  3Comments

iaincollins picture iaincollins  路  3Comments

dmi3y picture dmi3y  路  3Comments

iaincollins picture iaincollins  路  3Comments