Skip to content

Commit

Permalink
Merge pull request #11 from CL-Muadh/JWt
Browse files Browse the repository at this point in the history
jwt.strategy.ts
  • Loading branch information
Aakash-bhardwaj-cirruslabs authored Jun 27, 2024
2 parents 5097449 + ef039fd commit 73c323d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/humanoid-ai-backend/src/auth/jwt-auth.guard.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// src/auth/jwt-auth.guard.ts
import { Injectable } from '@nestjs/common';
import { AuthGuard } from '@nestjs/passport';

@Injectable()
export class JwtAuthGuard extends AuthGuard('jwt') {}
19 changes: 19 additions & 0 deletions apps/humanoid-ai-backend/src/auth/jwt.strategy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// src/auth/jwt.strategy.ts
import { Injectable } from '@nestjs/common';
import { PassportStrategy } from '@nestjs/passport';
import { ExtractJwt, Strategy } from 'passport-jwt';

@Injectable()
export class JwtStrategy extends PassportStrategy(Strategy) {
constructor() {
super({
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
ignoreExpiration: false,
secretOrKey: 'yourSecretKey', // replace with your secret key
});
}

async validate(payload: any) {
return { userId: payload.sub, username: payload.username };
}
}

0 comments on commit 73c323d

Please sign in to comment.