fix(next): ensures req.locale is populated before running access control (#10533)

Fixes #10529. The `req.locale` property within collection and global
access control functions does not reflect the current locale. This was
because we were attaching the locale to the req only _after_ running
`payload.auth`, which attempts to get access control without a
fully-formed req. The fix is to first authenticate the user using the
`executeAuthStrategies` operation directly, then determine the request
locale with that user, and finally get access results with the proper
locale.
This commit is contained in:
Jacob Fletcher
2025-01-13 10:33:27 -05:00
committed by GitHub
parent 6b051bd59e
commit afcc970e36
7 changed files with 90 additions and 35 deletions

View File

@@ -22,7 +22,7 @@ export interface Config {
'localized-required': LocalizedRequired;
'with-localized-relationship': WithLocalizedRelationship;
'relationship-localized': RelationshipLocalized;
dummy: Dummy;
'cannot-create-default-locale': CannotCreateDefaultLocale;
nested: Nested;
groups: Group;
tabs: Tab;
@@ -46,7 +46,7 @@ export interface Config {
'localized-required': LocalizedRequiredSelect<false> | LocalizedRequiredSelect<true>;
'with-localized-relationship': WithLocalizedRelationshipSelect<false> | WithLocalizedRelationshipSelect<true>;
'relationship-localized': RelationshipLocalizedSelect<false> | RelationshipLocalizedSelect<true>;
dummy: DummySelect<false> | DummySelect<true>;
'cannot-create-default-locale': CannotCreateDefaultLocaleSelect<false> | CannotCreateDefaultLocaleSelect<true>;
nested: NestedSelect<false> | NestedSelect<true>;
groups: GroupsSelect<false> | GroupsSelect<true>;
tabs: TabsSelect<false> | TabsSelect<true>;
@@ -378,8 +378,8 @@ export interface WithLocalizedRelationship {
value: string | LocalizedPost;
} | null)
| ({
relationTo: 'dummy';
value: string | Dummy;
relationTo: 'cannot-create-default-locale';
value: string | CannotCreateDefaultLocale;
} | null);
localizedRelationMultiRelationToHasMany?:
| (
@@ -388,8 +388,8 @@ export interface WithLocalizedRelationship {
value: string | LocalizedPost;
}
| {
relationTo: 'dummy';
value: string | Dummy;
relationTo: 'cannot-create-default-locale';
value: string | CannotCreateDefaultLocale;
}
)[]
| null;
@@ -398,9 +398,9 @@ export interface WithLocalizedRelationship {
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "dummy".
* via the `definition` "cannot-create-default-locale".
*/
export interface Dummy {
export interface CannotCreateDefaultLocale {
id: string;
name?: string | null;
updatedAt: string;
@@ -420,8 +420,8 @@ export interface RelationshipLocalized {
value: string | LocalizedPost;
} | null)
| ({
relationTo: 'dummy';
value: string | Dummy;
relationTo: 'cannot-create-default-locale';
value: string | CannotCreateDefaultLocale;
} | null);
relationMultiRelationToHasMany?:
| (
@@ -430,8 +430,8 @@ export interface RelationshipLocalized {
value: string | LocalizedPost;
}
| {
relationTo: 'dummy';
value: string | Dummy;
relationTo: 'cannot-create-default-locale';
value: string | CannotCreateDefaultLocale;
}
)[]
| null;
@@ -668,8 +668,8 @@ export interface PayloadLockedDocument {
value: string | RelationshipLocalized;
} | null)
| ({
relationTo: 'dummy';
value: string | Dummy;
relationTo: 'cannot-create-default-locale';
value: string | CannotCreateDefaultLocale;
} | null)
| ({
relationTo: 'nested';
@@ -1027,9 +1027,9 @@ export interface RelationshipLocalizedSelect<T extends boolean = true> {
}
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "dummy_select".
* via the `definition` "cannot-create-default-locale_select".
*/
export interface DummySelect<T extends boolean = true> {
export interface CannotCreateDefaultLocaleSelect<T extends boolean = true> {
name?: T;
updatedAt?: T;
createdAt?: T;