Skip to content

Commit d46e455

Browse files
committed
feat: add passaport jwt strategy
1 parent d3b09a9 commit d46e455

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { ExtractJwt, Strategy } from 'passport-jwt';
2+
import { PassportStrategy } from '@nestjs/passport';
3+
import { Injectable } from '@nestjs/common';
4+
import { ENVS } from '../../../../../environments';
5+
6+
@Injectable()
7+
export class JwtStrategy extends PassportStrategy(Strategy) {
8+
constructor() {
9+
super({
10+
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
11+
ignoreExpiration: false,
12+
secretOrKey: ENVS.JWT_TOKEN_SECRET,
13+
});
14+
}
15+
16+
async validate(payload: any) {
17+
return { userId: payload.sub, username: payload.username };
18+
}
19+
}

0 commit comments

Comments
 (0)