fix: use the slug for authentication header API Key
BREAKING CHANGE: replaced the useAPIKey authentication header format to use the collection slug instead of the collection label. Previous: `${collection.labels.singular} API-Key ${apiKey}`, updated: `${collection.slug} API-Key ${apiKey}`
This commit is contained in:
@@ -96,6 +96,31 @@ describe('Auth', () => {
|
||||
expect(data.user.email).toBeDefined();
|
||||
});
|
||||
|
||||
|
||||
it('should allow authentication with an API key with useAPIKey', async () => {
|
||||
const apiKey = '0123456789ABCDEFGH';
|
||||
const user = await payload.create({
|
||||
collection: slug,
|
||||
data: {
|
||||
email: 'dev@example.com',
|
||||
password: 'test',
|
||||
apiKey,
|
||||
},
|
||||
});
|
||||
const response = await fetch(`${apiUrl}/${slug}/me`, {
|
||||
headers: {
|
||||
...headers,
|
||||
Authorization: `${slug} API-Key ${user.apiKey}`,
|
||||
},
|
||||
});
|
||||
|
||||
const data = await response.json();
|
||||
|
||||
expect(response.status).toBe(200);
|
||||
expect(data.user.email).toBeDefined();
|
||||
expect(data.user.apiKey).toStrictEqual(apiKey);
|
||||
});
|
||||
|
||||
it('should refresh a token and reset its expiration', async () => {
|
||||
const response = await fetch(`${apiUrl}/${slug}/refresh-token`, {
|
||||
method: 'post',
|
||||
|
||||
Reference in New Issue
Block a user