From ece5a95f6473201c579759f452ca89581bc45e16 Mon Sep 17 00:00:00 2001 From: Riley Langbein <54197972+rilrom@users.noreply.github.com> Date: Fri, 3 Oct 2025 05:56:01 +0930 Subject: [PATCH] fix(next): prevent locale upsert when not authenticated (#13621) ### What? When `?locale=` is present in an admin panel URL and that admin panel URL is visited in an unauthenticated browser, a runtime error is thrown. ### Why? `upsertPreferences` relies on `req.user` to successfully create a new `payload-preferences` document. When an unauthenticated user visits a URL with a `locale` parameter, `upsertPreferences` is called but `req.user` is not available. ### How? Prevent `upsertPreferences` from being called when `req.user` is not available. Fixes #13581 Co-authored-by: Patrik Kozak <35232443+PatrikKozak@users.noreply.github.com> --- packages/next/src/utilities/getRequestLocale.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/next/src/utilities/getRequestLocale.ts b/packages/next/src/utilities/getRequestLocale.ts index 4643f1784..be6d636d0 100644 --- a/packages/next/src/utilities/getRequestLocale.ts +++ b/packages/next/src/utilities/getRequestLocale.ts @@ -13,7 +13,7 @@ export async function getRequestLocale({ req }: GetRequestLocalesArgs): Promise< if (req.payload.config.localization) { const localeFromParams = req.query.locale as string | undefined - if (localeFromParams) { + if (req.user && localeFromParams) { await upsertPreferences({ key: 'locale', req, value: localeFromParams }) }