0

I'm creating an login with NextAuth in my Next.js app.

Before I login, I restrict certain routes, only accessible if a user has been authorized. With NextAuth Credentials Provider, when an error is thrown, it automatically takes you to a template 404 page made by Next.js.

To prevent that, we can set redirect: false in the signIn object - and hence we remain on the login screen.

await signIn('credentials', 
    {
        redirect: false,
        email: email,
        password: password,
        callbackUrl: `${window.location.origin}/account`,
    }
);

When a user does login successfully, I want it to redirect to the /accounts page. This is what the callbackUrl takes care of - however, it looks like redirect is overriding the functionality of the callbackUrl.

Any ideas how to make both work?

  • Does this anwer your question: [How to handle login failed error in NextAuth.js?](https://stackoverflow.com/questions/70165993/how-to-handle-login-failed-error-in-nextauth-js)? You can't have both `redirect: false` and `callbackUrl` work, but you can manually redirect on successful login instead. – juliomalves Mar 27 '22 at 17:38

0 Answers0