Fix to use the stored data

This commit is contained in:
Owen
2026-04-02 21:57:59 -04:00
parent b7ccb92236
commit d5837ab718

View File

@@ -22,12 +22,21 @@ export async function getUserLocale(): Promise<Locale> {
const res = await internal.get("/user", await authCookieHeader()); const res = await internal.get("/user", await authCookieHeader());
const userLocale = res.data?.data?.locale; const userLocale = res.data?.data?.locale;
if (userLocale && locales.includes(userLocale as Locale)) { if (userLocale && locales.includes(userLocale as Locale)) {
// Set the cookie so subsequent requests don't need the API call // Try to cache in a cookie so subsequent requests skip the API
(await cookies()).set(COOKIE_NAME, userLocale, { // call. cookies().set() is only permitted in Server Actions and
maxAge: COOKIE_MAX_AGE, // Route Handlers — not during rendering — so we isolate it so
path: "/", // that a write failure doesn't prevent the locale from being
sameSite: "lax" // returned for the current request.
}); try {
(await cookies()).set(COOKIE_NAME, userLocale, {
maxAge: COOKIE_MAX_AGE,
path: "/",
sameSite: "lax"
});
} catch {
// Cannot set cookies in this context (e.g. during rendering);
// the correct locale is still returned below.
}
return userLocale as Locale; return userLocale as Locale;
} }
} catch { } catch {