feat: added beforeLogin hook (#1289)
This commit is contained in:
@@ -8,6 +8,9 @@ import { hooksSlug } from './collections/Hook';
|
||||
import { generatedAfterReadText, nestedAfterReadHooksSlug } from './collections/NestedAfterReadHooks';
|
||||
import { relationsSlug } from './collections/Relations';
|
||||
import type { NestedAfterReadHook } from './payload-types';
|
||||
import { hooksUsersSlug } from './collections/Users';
|
||||
import { devUser, regularUser } from '../credentials';
|
||||
import { AuthenticationError } from '../../src/errors';
|
||||
|
||||
let client: RESTClient;
|
||||
|
||||
@@ -117,4 +120,20 @@ describe('Hooks', () => {
|
||||
expect(retrievedDoc.group.subGroup.shouldPopulate.title).toEqual(relation.title);
|
||||
});
|
||||
});
|
||||
describe('auth collection hooks', () => {
|
||||
it('allow admin login', async () => {
|
||||
const { user } = await payload.login({
|
||||
collection: hooksUsersSlug,
|
||||
data: {
|
||||
email: devUser.email,
|
||||
password: devUser.password,
|
||||
},
|
||||
});
|
||||
expect(user).toBeDefined();
|
||||
});
|
||||
|
||||
it('deny user login', async () => {
|
||||
await expect(() => payload.login({ collection: hooksUsersSlug, data: { email: regularUser.email, password: regularUser.password } })).rejects.toThrow(AuthenticationError);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user