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:
Dan Ribbens
2022-12-18 19:10:01 -05:00
parent 0fbfe149df
commit 5b70ebd119
3 changed files with 31 additions and 6 deletions

View File

@@ -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',