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
This commit is contained in:
Patrik
2025-08-22 16:03:36 -04:00
committed by GitHub
parent 1e13474068
commit 810184269d
4 changed files with 116 additions and 1 deletions

View File

@@ -191,7 +191,11 @@ export const Auth: React.FC<Props> = (props) => {
} }
}, [modified]) }, [modified])
if (disableLocalStrategy && !enableFields && !useAPIKey) { const showAuthBlock = enableFields
const showAPIKeyBlock = useAPIKey && canReadApiKey
const showVerifyBlock = verify && isEditing
if (!(showAuthBlock || showAPIKeyBlock || showVerifyBlock)) {
return null return null
} }

View File

@@ -261,6 +261,33 @@ export default buildConfigWithDefaults({
}, },
], ],
}, },
{
slug: 'api-keys-with-field-read-access',
auth: {
disableLocalStrategy: true,
useAPIKey: true,
},
fields: [
{
name: 'enableAPIKey',
type: 'checkbox',
access: {
read: () => false,
},
},
{
name: 'apiKey',
type: 'text',
access: {
read: () => false,
},
},
],
labels: {
plural: 'API Keys With Field Read Access',
singular: 'API Key With Field Read Access',
},
},
], ],
onInit: seed, onInit: seed,
typescript: { typescript: {

View File

@@ -335,5 +335,30 @@ describe('Auth', () => {
}) })
}) })
}) })
describe('api-keys-with-field-read-access', () => {
let user
beforeAll(async () => {
url = new AdminUrlUtil(serverURL, 'api-keys-with-field-read-access')
user = await payload.create({
collection: apiKeysSlug,
data: {
apiKey: uuid(),
enableAPIKey: true,
},
})
})
test('should hide auth parent container if api keys enabled but no read access', async () => {
await page.goto(url.create)
// assert that the auth parent container is hidden
await expect(page.locator('.auth-fields')).toBeHidden()
await saveDocAndAssert(page)
})
})
}) })
}) })

View File

@@ -68,6 +68,7 @@ export interface Config {
'disable-local-strategy-password': DisableLocalStrategyPasswordAuthOperations; 'disable-local-strategy-password': DisableLocalStrategyPasswordAuthOperations;
'api-keys': ApiKeyAuthOperations; 'api-keys': ApiKeyAuthOperations;
'public-users': PublicUserAuthOperations; 'public-users': PublicUserAuthOperations;
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccessAuthOperations;
}; };
blocks: {}; blocks: {};
collections: { collections: {
@@ -77,6 +78,7 @@ export interface Config {
'api-keys': ApiKey; 'api-keys': ApiKey;
'public-users': PublicUser; 'public-users': PublicUser;
relationsCollection: RelationsCollection; relationsCollection: RelationsCollection;
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccess;
'payload-locked-documents': PayloadLockedDocument; 'payload-locked-documents': PayloadLockedDocument;
'payload-preferences': PayloadPreference; 'payload-preferences': PayloadPreference;
'payload-migrations': PayloadMigration; 'payload-migrations': PayloadMigration;
@@ -89,6 +91,7 @@ export interface Config {
'api-keys': ApiKeysSelect<false> | ApiKeysSelect<true>; 'api-keys': ApiKeysSelect<false> | ApiKeysSelect<true>;
'public-users': PublicUsersSelect<false> | PublicUsersSelect<true>; 'public-users': PublicUsersSelect<false> | PublicUsersSelect<true>;
relationsCollection: RelationsCollectionSelect<false> | RelationsCollectionSelect<true>; relationsCollection: RelationsCollectionSelect<false> | RelationsCollectionSelect<true>;
'api-keys-with-field-read-access': ApiKeysWithFieldReadAccessSelect<false> | ApiKeysWithFieldReadAccessSelect<true>;
'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>; 'payload-locked-documents': PayloadLockedDocumentsSelect<false> | PayloadLockedDocumentsSelect<true>;
'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>; 'payload-preferences': PayloadPreferencesSelect<false> | PayloadPreferencesSelect<true>;
'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>; 'payload-migrations': PayloadMigrationsSelect<false> | PayloadMigrationsSelect<true>;
@@ -114,6 +117,9 @@ export interface Config {
}) })
| (PublicUser & { | (PublicUser & {
collection: 'public-users'; collection: 'public-users';
})
| (ApiKeysWithFieldReadAccess & {
collection: 'api-keys-with-field-read-access';
}); });
jobs: { jobs: {
tasks: unknown; tasks: unknown;
@@ -210,6 +216,24 @@ export interface PublicUserAuthOperations {
password: string; password: string;
}; };
} }
export interface ApiKeysWithFieldReadAccessAuthOperations {
forgotPassword: {
email: string;
password: string;
};
login: {
email: string;
password: string;
};
registerFirstUser: {
email: string;
password: string;
};
unlock: {
email: string;
password: string;
};
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "users". * via the `definition` "users".
@@ -340,6 +364,18 @@ export interface RelationsCollection {
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "api-keys-with-field-read-access".
*/
export interface ApiKeysWithFieldReadAccess {
id: string;
updatedAt: string;
createdAt: string;
enableAPIKey?: boolean | null;
apiKey?: string | null;
apiKeyIndex?: string | null;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents". * via the `definition` "payload-locked-documents".
@@ -370,6 +406,10 @@ export interface PayloadLockedDocument {
| ({ | ({
relationTo: 'relationsCollection'; relationTo: 'relationsCollection';
value: string | RelationsCollection; value: string | RelationsCollection;
} | null)
| ({
relationTo: 'api-keys-with-field-read-access';
value: string | ApiKeysWithFieldReadAccess;
} | null); } | null);
globalSlug?: string | null; globalSlug?: string | null;
user: user:
@@ -392,6 +432,10 @@ export interface PayloadLockedDocument {
| { | {
relationTo: 'public-users'; relationTo: 'public-users';
value: string | PublicUser; value: string | PublicUser;
}
| {
relationTo: 'api-keys-with-field-read-access';
value: string | ApiKeysWithFieldReadAccess;
}; };
updatedAt: string; updatedAt: string;
createdAt: string; createdAt: string;
@@ -422,6 +466,10 @@ export interface PayloadPreference {
| { | {
relationTo: 'public-users'; relationTo: 'public-users';
value: string | PublicUser; value: string | PublicUser;
}
| {
relationTo: 'api-keys-with-field-read-access';
value: string | ApiKeysWithFieldReadAccess;
}; };
key?: string | null; key?: string | null;
value?: value?:
@@ -576,6 +624,17 @@ export interface RelationsCollectionSelect<T extends boolean = true> {
updatedAt?: T; updatedAt?: T;
createdAt?: T; createdAt?: T;
} }
/**
* This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "api-keys-with-field-read-access_select".
*/
export interface ApiKeysWithFieldReadAccessSelect<T extends boolean = true> {
updatedAt?: T;
createdAt?: T;
enableAPIKey?: T;
apiKey?: T;
apiKeyIndex?: T;
}
/** /**
* This interface was referenced by `Config`'s JSON-Schema * This interface was referenced by `Config`'s JSON-Schema
* via the `definition` "payload-locked-documents_select". * via the `definition` "payload-locked-documents_select".