-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.module.ts
More file actions
67 lines (60 loc) · 1.15 KB
/
Copy pathapp.module.ts
File metadata and controls
67 lines (60 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
import { Module, Controller, Get, UseGuards } from '@nestjs/common';
import { JwtDecode, JwtGuard, JwtScopesGuard } from './index';
import jsonwebtoken from 'jsonwebtoken';
class JwtVerifyGuard extends JwtGuard {
constructor() {
super((_decoded, jwt) => {
try {
jsonwebtoken.verify(jwt, 'shhhhh');
} catch {
return false;
}
});
}
}
@Controller()
export class AppController {
@UseGuards(new JwtVerifyGuard())
@Get('/verify')
verify() {
return {
success: true,
};
}
@UseGuards(new JwtGuard(({ role }) => role == 'admin'))
@Get('/admin')
admin() {
return {
success: true,
};
}
@UseGuards(new JwtScopesGuard(['users:admin']))
@Get('/users/:id')
profile() {
return {
success: true,
};
}
@Get()
getHello(@JwtDecode() jwtData) {
return {
success: true,
jwtData,
};
}
@Get('/decode')
decode(
@JwtDecode({ authorizationHeader: 'x-custom-authorization' }) jwtData,
) {
return {
success: true,
jwtData,
};
}
}
@Module({
imports: [],
controllers: [AppController],
providers: [],
})
export class AppModule {}