Skip to content

Setting the Signin CallbackUrl #1003

Answered by jaaneh
chr-ge asked this question in Help
Discussion options

You must be logged in to vote

You can pass a callbackUrl to the signIn() method, and use it like this:

<div onClick={() => signIn('twitter', { callbackUrl: 'http://localhost:3000/path/to/callback' })}>

You can also run custom checks on the login route and check for a session, then redirect if true. Example using getServerSideProps and passing providers to the signin component for creation of sign in buttons.

export const getServerSideProps = async ({ req }) => {
  const _providers = await providers()
  const session = await getSession({ req })

  if (session) {
    return {
      props: {},
      redirect: {
        destination: '/',
        permanent: false
      }
    }
  }

  return {
    props: {
      providers: _…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by chr-ge
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
3 participants