Make NextAuth consider i18n

I am defining a custom sign-in page in my app setting
pages: {
signIn: "/auth/login",
}
pages: {
signIn: "/auth/login",
}
in [...nextauth].ts. I am also using react-intl for i18n, and I want NextAuth to localize this route as well. So when I have no valid session and route to a German route like /de/foo which needs auth, the signIn methods gets called, I get rerouted to my sign-in page, but my current locale gets lost. How can I make NextAuth remember my current locale, so I get redirected to /de/auth/login instead of plain /auth/login?
1 Reply
Froxx
FroxxOP2y ago
I'm not sure about how much this is in the NextAuth team's mind, but replacing the signIn() call with
router.push({
pathname: "/auth/login",
query: { callbackUrl: router.pathname },
});
router.push({
pathname: "/auth/login",
query: { callbackUrl: router.pathname },
});
does the job. Keep in mind this is just the signIn call without parameters in my route guard, so I get redirected to the login page – not the signIn call on my login page that actually signs me in (e.g. signIn("credentials", { username: "foo", password: "bar" }))
Want results from more Discord servers?
Add your server