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
0
votes
0 answers

problems with unit test nestjs using Firebase Functions locally

[[enter image description here](https://i.stack.imgur.com/dJNjz.jpg)](https://i.stack.imgur.com/SkoTq.jpg) Hello, good evening, could you please help me with a unit test I am doing in NestJS using Firebase Functions locally? I have been reading the…
0
votes
1 answer

While implementing RBAC in nest js i'm getting the error ("TypeError: Cannot read properties of undefined (reading 'roles')")

I'm struggling with the error (TypeError: Cannot read properties of undefined (reading 'roles') when i try to implement RBAC using nest here's my code. Im unable to sort out the error and im struggling with this error from 2 weeks. Please help me in…
Vamsi
  • 13
  • 4
0
votes
1 answer

NestJS empty JWT token

A new user is created without a jwt token. An empty token is returned I don't understand what the problem is. Help me please. Himself frontend developer and backend for study. Don't scold too…
Deemoonn
  • 3
  • 3
0
votes
1 answer

Nestjs - pass exception from guard to filter

I wrote a custom JWT guard from which I am throwing an error if I find that an access token is missing from the a request cookie. Problem is, I want to return an UnauthorizedException with a custom message to my React client, instead of…
asus
  • 1,427
  • 3
  • 25
  • 59
0
votes
1 answer

property signin, sign up does not exist on type AuthService

auth.controller file `import { Test, TestingModule } from '@nestjs/testing'; import { AuthController } from './auth.controller'; describe('AuthController', () => { let controller: AuthController; beforeEach(async () => { const module:…
0
votes
0 answers

Is it safe if the credential is included in request body

I wonder why the user credential is included in the request body when I authenticate the user's JWT with using passport? enter image description here enter image description here I suppose it's not safe to include the credential in the request ? How…
0
votes
1 answer

How to get JWT payload from different key rather than req.user in NestJS

The way to get payload after the guard is like what this tutorial mentioned. @UseGuards(JwtAuthGuard) @Get('profile') getProfile(@Request() req) { return req.user; } Basically, you can access the payload with the object key user in the…
Chris Kao
  • 410
  • 4
  • 12
0
votes
1 answer

NestJs Guards Order

I have problems with NestJs Guards, despite the correct order which I got from here: https://docs.nestjs.com/faq/request-lifecycle there still seems to be problems. I am aware that the AuthGuard binds the user to the request via the password…
0
votes
0 answers

secretKeyOrPrivateKey must required error

I have given value of secretKeyOrPrivateKey value but same error again and again. Please use this link for ref : https://docs.nestjs.com/security/authentication
0
votes
2 answers

secretOrPrivateKey must have a value in @nestjs/jwt

I can not get a token.I am using import { JwtService } from '@nestjs/jwt';.The package version is "@nestjs/jwt": "^9.0.0".The this.jwtService.sign(payload) function takes only one parameter. It shows error that I have been giving below. Error:…
Md.Shakil Shaikh
  • 347
  • 4
  • 11
0
votes
1 answer

Multiple overrideGuard configurations resulting into tests failures

I have a nestjs application and some nestjs tests written in jest and they make use of guards. So in the tests i have created fake guards and trying to override them. Due to multiple overrideGuard configurations I am seeing test failures and my test…
SRJ
  • 2,092
  • 3
  • 17
  • 36
0
votes
1 answer

How to excecute guard before injected provider into Scope.Request

I am working on a multi-tenant app using NestJS and I store the tenantId in the token using Jwt, I need to create a database tenant connection before I do database operations but the provider(code below) is being executed before the JwtAuthGuard but…
Manuvo
  • 748
  • 5
  • 15
0
votes
0 answers

NestJS Authentication - Passport strategy, JWT creation problem

I'm following the official NestJS documentation. Currently, I'm trying to implement the authentication step with Passport strategy. I did every step, as the documentation says, but I got stuck where I need to generate the JWT with the…
0
votes
1 answer

How are Guards and Strategies exactly working under the hood in Nestjs?

I am new to Nestjs and I am using guards, strategies and passport for authentification. I don't understand what's going on under the hood. I have a guard for a refreshToken mutation: import { AuthGuard } from '@nestjs/passport'; import {…
69JonDoe69
  • 41
  • 1
  • 6
0
votes
1 answer

user is undefined in request pipeline - Nestjs

I have a controller which has an authentication guard and a RBAC authorization guard @Get('get-framework-lists') @UseGuards(JwtAuthGuard) // authentication guard @Roles(Role.SO) // RBAC authorization guard getFrameworkListsByCompany() { return…
vaibhav deep
  • 655
  • 1
  • 8
  • 27