Skip to content

Commit 8101842

Browse files
authored
fix(ui): auth-fields container renders despite no visible auth/API key/verify content (#13554)
### What? Prevents the Auth component from rendering an empty `.auth-fields` wrapper. ### Why? When `disableLocalStrategy` is true and `enableFields` is false, but `useAPIKey` is true while read access to API key fields is denied, the component still rendered the parent wrapper with a background—showing a blank box. ### How? Introduce `hasVisibleContent`: - `showAuthBlock = enableFields` - `showAPIKeyBlock = useAPIKey && canReadApiKey` - `showVerifyBlock = verify && isEditing` If none are true, return `null`. (`disableLocalStrategy` is already accounted for via `enableFields`.) Fixes #12089 --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1211117270523574
1 parent 1e13474 commit 8101842

File tree

4 files changed

+116
-1
lines changed

4 files changed

+116
-1
lines changed

packages/ui/src/views/Edit/Auth/index.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,11 @@ export const Auth: React.FC<Props> = (props) => {
191191
}
192192
}, [modified])
193193

194-
if (disableLocalStrategy && !enableFields && !useAPIKey) {
194+
const showAuthBlock = enableFields
195+
const showAPIKeyBlock = useAPIKey && canReadApiKey
196+
const showVerifyBlock = verify && isEditing
197+
198+
if (!(showAuthBlock || showAPIKeyBlock || showVerifyBlock)) {
195199
return null
196200
}
197201

test/auth/config.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,33 @@ export default buildConfigWithDefaults({
261261
},
262262
],
263263
},
264+
{
265+
slug: 'api-keys-with-field-read-access',
266+
auth: {
267+
disableLocalStrategy: true,
268+
useAPIKey: true,
269+
},
270+
fields: [
271+
{
272+
name: 'enableAPIKey',
273+
type: 'checkbox',
274+
access: {
275+
read: () => false,
276+
},
277+
},
278+
{
279+
name: 'apiKey',
280+
type: 'text',
281+
access: {
282+
read: () => false,
283+
},
284+
},
285+
],
286+
labels: {
287+
plural: 'API Keys With Field Read Access',
288+
singular: 'API Key With Field Read Access',
289+
},
290+
},
264291
],
265292
onInit: seed,
266293
typescript: {

test/auth/e2e.spec.ts

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,5 +335,30 @@ describe('Auth', () => {
335335
})
336336
})
337337
})
338+
339+
describe('api-keys-with-field-read-access', () => {
340+
let user
341+
342+
beforeAll(async () => {
343+
url = new AdminUrlUtil(serverURL, 'api-keys-with-field-read-access')
344+
345+
user = await payload.create({
346+
collection: apiKeysSlug,
347+
data: {
348+
apiKey: uuid(),
349+
enableAPIKey: true,
350+
},
351+
})
352+
})
353+
354+
test('should hide auth parent container if api keys enabled but no read access', async () => {
355+
await page.goto(url.create)
356+
357+
// assert that the auth parent container is hidden
358+
await expect(page.locator('.auth-fields')).toBeHidden()
359+
360+
await saveDocAndAssert(page)
361+
})
362+
})
338363
})
339364
})

test/auth/payload-types.ts

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ export interface Config {
6868
'disable-local-strategy-password': DisableLocalStrategyPasswordAuthOperations;
6969
'api-keys': ApiKeyAuthOperations;
7070
'public-users': PublicUserAuthOperations;
71+
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccessAuthOperations;
7172
};
7273
blocks: {};
7374
collections: {
@@ -77,6 +78,7 @@ export interface Config {
7778
'api-keys': ApiKey;
7879
'public-users': PublicUser;
7980
relationsCollection: RelationsCollection;
81+
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccess;
8082
'payload-locked-documents': PayloadLockedDocument;
8183
'payload-preferences': PayloadPreference;
8284
'payload-migrations': PayloadMigration;
@@ -89,6 +91,7 @@ export interface Config {
8991
'api-keys': ApiKeysSelect<false> | ApiKeysSelect<true>;
9092
'public-users': PublicUsersSelect<false> | PublicUsersSelect<true>;
9193
relationsCollection: RelationsCollectionSelect<false> | RelationsCollectionSelect<true>;
94+
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccessSelect<false> | ApiKeysWithFieldReadAccessSelect<true>;
9295
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
9396
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
9497
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@@ -114,6 +117,9 @@ export interface Config {
114117
})
115118
| (PublicUser & {
116119
collection: 'public-users';
120+
})
121+
| (ApiKeysWithFieldReadAccess & {
122+
collection: 'api-keys-with-field-read-access';
117123
});
118124
jobs: {
119125
tasks: unknown;
@@ -210,6 +216,24 @@ export interface PublicUserAuthOperations {
210216
password: string;
211217
};
212218
}
219+
export interface ApiKeysWithFieldReadAccessAuthOperations {
220+
forgotPassword: {
221+
email: string;
222+
password: string;
223+
};
224+
login: {
225+
email: string;
226+
password: string;
227+
};
228+
registerFirstUser: {
229+
email: string;
230+
password: string;
231+
};
232+
unlock: {
233+
email: string;
234+
password: string;
235+
};
236+
}
213237
/**
214238
* This interface was referenced by `Config`'s JSON-Schema
215239
* via the `definition` "users".
@@ -340,6 +364,18 @@ export interface RelationsCollection {
340364
updatedAt: string;
341365
createdAt: string;
342366
}
367+
/**
368+
* This interface was referenced by `Config`'s JSON-Schema
369+
* via the `definition` "api-keys-with-field-read-access".
370+
*/
371+
export interface ApiKeysWithFieldReadAccess {
372+
id: string;
373+
updatedAt: string;
374+
createdAt: string;
375+
enableAPIKey?: boolean | null;
376+
apiKey?: string | null;
377+
apiKeyIndex?: string | null;
378+
}
343379
/**
344380
* This interface was referenced by `Config`'s JSON-Schema
345381
* via the `definition` "payload-locked-documents".
@@ -370,6 +406,10 @@ export interface PayloadLockedDocument {
370406
| ({
371407
relationTo: 'relationsCollection';
372408
value: string | RelationsCollection;
409+
} | null)
410+
| ({
411+
relationTo: 'api-keys-with-field-read-access';
412+
value: string | ApiKeysWithFieldReadAccess;
373413
} | null);
374414
globalSlug?: string | null;
375415
user:
@@ -392,6 +432,10 @@ export interface PayloadLockedDocument {
392432
| {
393433
relationTo: 'public-users';
394434
value: string | PublicUser;
435+
}
436+
| {
437+
relationTo: 'api-keys-with-field-read-access';
438+
value: string | ApiKeysWithFieldReadAccess;
395439
};
396440
updatedAt: string;
397441
createdAt: string;
@@ -422,6 +466,10 @@ export interface PayloadPreference {
422466
| {
423467
relationTo: 'public-users';
424468
value: string | PublicUser;
469+
}
470+
| {
471+
relationTo: 'api-keys-with-field-read-access';
472+
value: string | ApiKeysWithFieldReadAccess;
425473
};
426474
key?: string | null;
427475
value?:
@@ -576,6 +624,17 @@ export interface RelationsCollectionSelect<T extends boolean = true> {
576624
updatedAt?: T;
577625
createdAt?: T;
578626
}
627+
/**
628+
* This interface was referenced by `Config`'s JSON-Schema
629+
* via the `definition` "api-keys-with-field-read-access_select".
630+
*/
631+
export interface ApiKeysWithFieldReadAccessSelect<T extends boolean = true> {
632+
updatedAt?: T;
633+
createdAt?: T;
634+
enableAPIKey?: T;
635+
apiKey?: T;
636+
apiKeyIndex?: T;
637+
}
579638
/**
580639
* This interface was referenced by `Config`'s JSON-Schema
581640
* via the `definition` "payload-locked-documents_select".

0 commit comments

Comments
 (0)