Skip to content

Commit ece5a95

Browse files
rilromPatrikKozak
andauthored
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>
1 parent d826159 commit ece5a95

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

packages/next/src/utilities/getRequestLocale.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ export async function getRequestLocale({ req }: GetRequestLocalesArgs): Promise<
1313
if (req.payload.config.localization) {
1414
const localeFromParams = req.query.locale as string | undefined
1515

16-
if (localeFromParams) {
16+
if (req.user && localeFromParams) {
1717
await upsertPreferences<Locale['code']>({ key: 'locale', req, value: localeFromParams })
1818
}
1919

0 commit comments

Comments
 (0)