You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Your question
How to maintain the locale intact using NextAuth.js and Sub-path Routing?
What are you trying to do
Next.js v10 introduced built-in support for internalization. I use this functionality for my application and specifically the Sub-path Routing. To give you an example, the default locale is English and does not have a prefix (https://www.example.com/blog) and the Greek locale has the el prefix (https://www.example.com/el/blog). When I change the route to e.g. /support The Next Router will keep the prefix intact and redirect the user to https://www.example.com/el/support. I have integrated NextAuth in my application and I have created a custom login page and also a page where new users land to setup their profile for the first time. For that, I used the following pages options:
Let's assume that the user is in the Greek locale. When he selects to login, I use the singin api and NextAuth will redirect the user to https://www.example.com/auth/signin instead of https://www.example.com/el/auth/signin. This, of course, results in a change of the locale and the user will land in a page that is in English instead of Greek. I bypassed this issue by using the Next Router to redirect to /auth/signin and the callbackURL option of the signin api (thus I am not letting NextAuth do the routing). What I cannot resolve is the newUser redirect that occurs only for newly created users. As you can imagine I faced the same issue and the user ends up in https://www.example.com/account/setup instead of https://www.example.com/el/account/setup. I tried using callbacks but I couldn't make it work properly. Is there anything I can do to resolve this localization issue?
Feedback Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
This discussion was converted from issue #938 on December 09, 2020 16:14.
Heading
Bold
Italic
Quote
Code
Link
Numbered list
Unordered list
Task list
Attach files
Mention
Reference
Menu
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Your question
How to maintain the locale intact using NextAuth.js and Sub-path Routing?
What are you trying to do
Next.js v10 introduced built-in support for internalization. I use this functionality for my application and specifically the Sub-path Routing. To give you an example, the default locale is English and does not have a prefix (https://www.example.com/blog) and the Greek locale has the el prefix (https://www.example.com/el/blog). When I change the route to e.g. /support The Next Router will keep the prefix intact and redirect the user to https://www.example.com/el/support. I have integrated NextAuth in my application and I have created a custom login page and also a page where new users land to setup their profile for the first time. For that, I used the following pages options:
Let's assume that the user is in the Greek locale. When he selects to login, I use the singin api and NextAuth will redirect the user to https://www.example.com/auth/signin instead of https://www.example.com/el/auth/signin. This, of course, results in a change of the locale and the user will land in a page that is in English instead of Greek. I bypassed this issue by using the Next Router to redirect to /auth/signin and the callbackURL option of the signin api (thus I am not letting NextAuth do the routing). What I cannot resolve is the newUser redirect that occurs only for newly created users. As you can imagine I faced the same issue and the user ends up in https://www.example.com/account/setup instead of https://www.example.com/el/account/setup. I tried using callbacks but I couldn't make it work properly. Is there anything I can do to resolve this localization issue?
Feedback
Documentation refers to searching through online documentation, code comments and issue history. The example project refers to next-auth-example.
Beta Was this translation helpful? Give feedback.
All reactions