mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-17 23:52:24 +00:00
fix(demo): keep a visitor's language off the shared account
The session read copies the language cookie into the account row when the two differ, so on a demo every visitor's language still landed on the one account all visitors share, although the locale route already left the row alone there. Under DEMO_MODE the session read now answers in the visitor's language and writes nothing. The route's unit test mocked the database and the handler wholesale; both paths are now proved against Postgres and read back from the row.
This commit is contained in:
1 parent
0278b6045e
commit
18e8990638
3 files changed
+108
-79
No files matched your search
+12
-6
@@ -430,12 +430,18 @@ export async function getSession(): Promise<{
|
||||
// already had, and it is coherent: that browser is showing the older
|
||||
// language too, because the cookie outranks the column on its first
|
||||
// paint as well.
|
||||
void prisma.user
|
||||
.update({
|
||||
where: { id: session.user.id },
|
||||
data: { locale: cookieLocale },
|
||||
})
|
||||
.catch(() => {});
|
||||
//
|
||||
// A demo is one account every visitor shares: there the language stays
|
||||
// in this visitor's cookie and never reaches the row the next visitor
|
||||
// starts from.
|
||||
if (process.env.DEMO_MODE !== "true") {
|
||||
void prisma.user
|
||||
.update({
|
||||
where: { id: session.user.id },
|
||||
data: { locale: cookieLocale },
|
||||
})
|
||||
.catch(() => {});
|
||||
}
|
||||
// Keep THIS request coherent — a handler resolving the locale from the
|
||||
// returned row must not answer with the value we just replaced.
|
||||
session.user.locale = cookieLocale;
|
||||
|
||||
Reference in new issue
Block a user