Browse Source

introduce the jwt strategy

Sven Czarnian 2 years ago
parent
commit
0827ccd1b1
1 changed files with 19 additions and 0 deletions
  1. 19 0
      src/auth/strategies/jwt.strategy.ts

+ 19 - 0
src/auth/strategies/jwt.strategy.ts

@@ -0,0 +1,19 @@
+import { PassportStrategy } from '@nestjs/passport';
+import { Injectable } from '@nestjs/common';
+import { ConfigService } from '@nestjs/config';
+import { ExtractJwt, Strategy } from 'passport-jwt';
+
+@Injectable()
+export class JwtStrategy extends PassportStrategy(Strategy) {
+  constructor(config: ConfigService) {
+    super({
+      jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
+      ignoreExpiration: false,
+      secretOrKey: config.get<string>('server.jwt-secret'),
+    });
+  }
+
+  async validate(payload: any) {
+    return { userId: payload.sub, vatsimId: payload.vatsimId };
+  }
+}