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?