Questions tagged [nestjs-jwt]

This package provides JSON Web Token (JWT) utilities and helps create tokens for use in authentication and authorization of web requests to your NestJS application. It contains a JwtModule that exposes a single JwtService provider to sign, verify and decode JWT tokens, either synchronously or asynchronously. The JwtService is configured with options (via JwtModuleOptions) that correspond to config of the NodeJS jsonwebtoken package used underneath.

Provides JWT utilities module for NestJS based on the jsonwebtoken package.

From the documentation:

The @nestjs/jwt package is a utility package that helps with JWT manipulation. The passport-jwt package is the Passport package that implements the JWT strategy and @types/passport-jwt provides the TypeScript type definitions.

From the project README.md:

Installation

$ npm i --save @nestjs/jwt

Usage

Import JwtModule:

@Module({
 imports: [JwtModule.register({ secret: 'hard!to-guess_secret' })],
 providers: [...],
})
export class AuthModule {}

Inject JwtService:

@Injectable()
export class AuthService {
 constructor(private readonly jwtService: JwtService) {}
}

More information

77 questions
1
vote
1 answer

Nestjs JwtStrategy access to context

I have a UseGuard in my WebSocket. Actually, this guard is a JwtAuthGuard that extends AuthGuard('jwt'). The JwtAuthGuard has a Strategy class called JwtStrategy. In this class, I have a validate method. In HTTP-based requests I return payload in…
Vahid Najafi
  • 4,654
  • 11
  • 43
  • 88
1
vote
1 answer

NestJs authentication with JWT strategy - add validation option of "ignoreNotBefore"

I am using an AuthGuard in NestJs to validate the requests jwt token. Because of my service is only validate the token and not created it, It must not use the "nbf" validation in order to avoid cases the the time of the server which creates the…
user2436448
  • 445
  • 4
  • 7
  • 18
1
vote
1 answer

How can we access decorator from a service class in NestJS

I am new in NestJS and trying to do auth system. I was able to do. So here is what I am doing to get access to auth. In my controller I have @Get('/user') async getUser(@AuthUser() token: string) : Promise { return…
Hkm Sadek
  • 2,987
  • 9
  • 43
  • 95
1
vote
2 answers

nestjs extends jwt guard

i have extended jwt guard for purpose of checking if user exists in user table here's my code: import { ExecutionContext, Injectable, UnauthorizedException, } from '@nestjs/common'; import { AuthGuard } from '@nestjs/passport'; import { error…
imedin
  • 13
  • 1
  • 3
1
vote
2 answers

How to protect proxy with guards in NestJS

Using http-proxy-middleware (which uses http-proxy) I was able to create proxy to an internal (hidden from outside) url and get expected response. However, since this is middleware approach, I am not able to apply any existing Guards (eg, JWT, Role…
hoistyler
  • 222
  • 3
  • 12
1
vote
1 answer

NestJS - How to create wrapping service over jwt service (from jwt module)

Sorry for my bad english, I'm from Ukraine :) Could you tell me how can I create my own service, that extends of Jwt service provided jwt module from npm package? I want to create my own JwtService for catch errors and isolate duplicate logic for…
1
vote
1 answer

The jwt service this.jwtService.sign is not a function

With this code in AuthService: @Injectable() AuthService { constructor( @InjectRepository(UserRepository) private jwtService: JwtService private userRepository: UserRepository ) { } async login(loginCredentialsDto:…
Darwins
  • 53
  • 5
1
vote
2 answers

authentication using nestjs, passport with JWT strategy

I'm trying to implement a nestjs authentication and authorization for a tasks app I'm using JWT strategy with passport But I Cannot implement logout method I tried @Get('/logout') logout(@Request() req) { req.logout(); } it returns 200 but then…
Omar Abdelhady
  • 1,528
  • 4
  • 19
  • 31
0
votes
0 answers

NestJS - RBAC authorization guard with dynamic permissions

` Super Admin - create users, create admin, read, create, delete : all organizations Admin - read, create, delete : all organizations User - read, create, delete : specific organizations Role Schema name : superAdmin/admin/user permissions :…
0
votes
0 answers

Is it secure to revoke JWT via "secret" saved in the DB?

First of all, I'm still relatively new to the topic security and might not think of some aspects. Recently, I've been working on an API with JWT authentication, but now I need to revoke the tokens on-demand instead of waiting until they expire…
0
votes
1 answer

How to validate a JWT token using a JWKS (JSON) public key

I'm trying to write a service that will take a JWT token and verify it using a public key that's in the JWKS JSON format. I believe I can grab the key and convert it into a KeyObject (no idea if this is necessary), but I can't quite figure out how…
Mike Christensen
  • 88,082
  • 50
  • 208
  • 326
0
votes
1 answer

How to integrate NestJS/passport with React Native/Expo?

As the title suggests, what is the correct mental model for integrating NestJS/passport authentication and authorization with a React Native app? For context, I'm not that familiar with JWT but trying to learn, and right now my react native/expo app…
TLS
  • 31
  • 4
0
votes
0 answers

How to make APP_GUARD run before any Imports module in NestJS

I have a JWT validate middleware like bellow app.module.ts @Module({ imports: [ MongooseModule.forRoot(global.SkeletonConfig.MONGODB_URI), UserModule, ], providers: [ { provide: APP_GUARD, useClass: AuthGuard, }, …
vy.pham
  • 571
  • 6
  • 20
0
votes
1 answer

Can't set cookie in response NestJs

I Have a nestjs graphQL auth microservice and trying to set a http only cookie containing the token, and for some reason setting the cookie doesn't work, i get this error: { "errors": [ { "message": "response.cookie is not a function", …
saafgh
  • 33
  • 8
0
votes
0 answers

Optimal Authentication Approach for a NestJS, GraphQL, and Vue.js SaaS Application

We are in the process of developing a SaaS application with an offline-first approach. Our technology stack comprises NestJS (Node.js), GraphQL, and Vue.js (Single Page Application). We're currently grappling with an authentication conundrum that…