Redirect after successful sign in or sign up for credentials type in next auth

Viewed 5695

Is there any examples and/or way to redirect to private dashboard on successful sign in or sign up for credentials type in next-auth? I couldn't find any clear docs around this.

I was looking at adding redirect below but wasn't sure if it was the right approach:

callbacks.signIn = async (data, account, profile) => {
  if ((account.provider === 'google' && profile.verified_email === true) || (account.type === 'credentials' && data.status === 200)) {
    return Promise.resolve(true)
  } else {
    return Promise.resolve(false)
  }
}
2 Answers

This can actually happen when initiating the signin. From the docs., you can pass a callback URL to the sign in. you code will look like this.

  signIn(provider.id, {
      callbackUrl: `${window.location.origin}/protected`,
    })
Related