Skip to content

Commit a745c9c

Browse files
committed
chore: release v2
BREAKING CHANGE: Total rewrite of many things
1 parent 3c93e54 commit a745c9c

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

example/app.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ export default await AppContainer.create({
1616
inject: [CryptoService],
1717
useFactory: (cryptoService: CryptoService) => {
1818
return {
19-
defineAbility: (ability) => {
20-
ability.can('manage', 'all');
19+
defineAbility: (ability, payload: { isAdmin: boolean }) => {
20+
if (payload.isAdmin) {
21+
ability.can('manage', 'all');
22+
}
2123
},
2224
loginCredentialsSchema: z.object({
2325
password: z.string().min(1),
@@ -29,7 +31,9 @@ export default await AppContainer.create({
2931
}
3032
return {
3133
hashedPassword: await cryptoService.hashPassword('password'),
32-
tokenPayload: {}
34+
tokenPayload: {
35+
isAdmin: true
36+
}
3337
};
3438
}
3539
};

src/modules/auth/__tests__/auth.module.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import { AuthModule } from '../auth.module.js';
1818
import { JwtStrategy } from '../strategies/jwt.strategy.js';
1919

2020
import type { BaseEnv } from '../../../schemas/env.schema.js';
21-
import type { DefineAbility } from '../auth.config.js';
21+
import type { DefineAbility, UserQuery } from '../auth.config.js';
2222

2323
@Controller('cats')
2424
class CatsController {
@@ -43,7 +43,7 @@ describe('AuthModule', () => {
4343
let jwtStrategy: JwtStrategy;
4444

4545
let defineAbility: Mock<DefineAbility>;
46-
let userQuery: Mock;
46+
let userQuery: Mock<UserQuery>;
4747

4848
const loginCredentials = {
4949
password: 'password',
@@ -66,7 +66,7 @@ describe('AuthModule', () => {
6666
password: z.string(),
6767
username: z.string()
6868
}),
69-
userQuery
69+
userQuery: userQuery
7070
}),
7171
ConfigModule.forRoot({
7272
envConfig: {
@@ -113,7 +113,7 @@ describe('AuthModule', () => {
113113

114114
it('should return status code 401 if the hashed password is incorrect', async () => {
115115
const comparePassword = vi.spyOn(CryptoService.prototype, 'comparePassword');
116-
userQuery.mockResolvedValueOnce({ hashedPassword: '123$123' });
116+
userQuery.mockResolvedValueOnce({ hashedPassword: '123$123', tokenPayload });
117117
const response = await request(server).post('/auth/login').send(loginCredentials);
118118
expect(response.status).toBe(401);
119119
expect(userQuery).toHaveBeenCalledExactlyOnceWith(loginCredentials);

0 commit comments

Comments
 (0)