How to persist next-intl locale during social-provider sign-up?
I can’t figure out how to reliably save the user’s locale during social-provider sign-up (Google, GitHub, etc.).
My app uses next-intl, so the locale is always a path param (/en/…, /cs/…).
With email+password I simply send locale in the body, but OAuth redirects lose this value.
Current attempt
Client (Next.js 15 + better-auth 1.3.2):
Server after hook:
What I’m missing
-How should I forward the locale so the callback handler can read it?
-Which exact path (/callback/:provider?) and which field (query.state, query.locale, body?) should I check?
-Is there a built-in way to pass arbitrary data (like locale) through the OAuth flow, or must I use cookies / custom state?
Happy to refactor the code—just need the canonical pattern.
Thanks!
Solution:Jump to solution
Solution:
```
if (ctx.path.startsWith("/callback/")) { //Here just use a /callback/ to catch all OAuth routes
const newSession = ctx.context.newSession ?? ctx.context.session;
if (newSession) {...
13 Replies
I think the best solution is to store the user's locale in cookies
So you'll be able to get it in any request
I store in a cookies but i am not able to get locale from it. I will show this approach also a bit later, not at home
@Vlad i had a function
Which i was using to get cookies inside my after hook
But it have not worked, i was getting a default "en" locale in all cases
You should do
const locale = ctx.getCookie("NEXT_LOCALE")

so not to use a custom function but instead try to access cookies from a context? I would try
Cookies()
, headers()
, etc work only in server actions or route handlers
Yeah@Vlad getting null from newSession
someone? 😦
Try to log all context and see what's there
in this code i dont even see a logs lol. may it be coz i am not hitting path "/callback/google" or console.log(ctx.context) runs on a client so while i am getting fast redirect i cant see a logs in a console?
First you check if it starts with sign-up, then you check if it equals, that's why it never runs that if
Just log the context at the start of the function
thank you, it helped a lot to understand how ctx works. i found out that my path was wrong and now i successfully can update a locale by cookies. thank you man
Пожалуйста)
Solution
Solution: