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
1 answer

Property 'pipe' does not exist on type 'Promise

I`m developing auth guard in nestjs, I got This error. If I call .pipe() async validateUser(email: string, password: string): Promise { const findUser = await this.userRepository.findOneBy({email: email, password: password }); …
Anas Isah
  • 47
  • 7
0
votes
0 answers

How to get User Access Control in NestJs Guard for authorizations?

I am new in @Nestjs. I am using graphql in @Nestjs. I have a question in this field. How can I access UserSchema or UserModel from AuthGuard.ts? Here in AuthGuard.ts I am checking request context headers is and verify jwt token- import { Injectable,…
0
votes
1 answer

NestJS module import not working in the forRootAsync and forRootMethod of a dynamic module

When trying to import another module inside of my dynamic modules nest throws the following error when using a service exported by that module inside of my services: Error: Nest can't resolve dependencies of the ActivationService (UsersService, ?,…
0
votes
1 answer

Dynamic ConfigModule cannot Inject in custom JwtModule

I created my Dynamic configModule to extract environment variables from a different path. It extracts from an yml file. Everything works properly if a add in some module. Here is my ConfigModule: import { DynamicModule } from…
DustInTheSilence
  • 575
  • 1
  • 7
  • 15
0
votes
1 answer

How to implement 'Remember me' feature in NestJS framework with JWT strategy

I'm trying to implement the remember me feature using NestJS framework, I already have the Jwt and local strategy implemented and working like this: import { ExtractJwt, Strategy } from 'passport-jwt'; import { PassportStrategy } from…
0
votes
0 answers

Role based Auhtorization is not working as expected in nestjs

I have followed the NestJs documentation and added the following rolebased auth guards which is not working. I always get headers undefined or context.switchToHttp().getRequest() is undefined. I am using graphql with nestjs. My…
Yashwanth Kata
  • 817
  • 8
  • 21
0
votes
1 answer

Not able to load environment specific config in NestJS

I have created three env files : .env ,.env.test,.env.prod in my root directory. .env file…
Yashwanth Kata
  • 817
  • 8
  • 21
0
votes
1 answer

createParamDecorator VS CanActivate in Nestjs for authorization

I'm trying to authorize users based on their permissions. Is there any difference in functionality between using createParamDecorator and CanActivate method? export const GetUser = createParamDecorator((data: string, ctx: ExecutionContext) : User =>…
sinister
  • 3
  • 2
0
votes
0 answers

AuthGuard broken after NestJS Update

I have a NestJS (version 6) project that implemented authentication using jwt. The following config worked fine: package.json ... “@nest-modules/mailer”: “^1.1.3", “@nestjs/common”: “^6.6.7", “@nestjs/core”: “^6.6.7", “@nestjs/jwt”:…
0
votes
2 answers

How to implement clinic.js in Nest JS Framework (typescript)

I implemented Clinic.js in Node JS. But I don't know how to implement clinic.js in Nest JS Framework. I explore it how to implement clinic.js to Nest JS. But I couldn't get any answer can you please tell me.
0
votes
1 answer

How to generate migration file in typeorm using nest js

I am new this framework Nest JS and created sample Restful API but could not migrate the entity file. I tried many ways it's not working. first time run migration command to generate migration file it's working fine. but second time creating a new…
0
votes
2 answers

How to setup different environment file in nest js using postgresql

I am new this framework. I connected PostgreSQL database using ormconfig file. but I need to configure development environment, production environment, test environment. How to achieve this scenarios. I tried to use config service in my project. but…
0
votes
0 answers

ExecuteContext cannot get User in Class RoleGuard

import { ROLES_KEY } from './role.decorator'; import { UserRole } from '../users/role.enum'; import { CanActivate, Injectable, ExecutionContext } from '@nestjs/common'; import { Reflector } from '@nestjs/core'; @Injectable() export class RolesGuard…
BlueDragon
  • 57
  • 1
  • 7
0
votes
1 answer

How to get NestJS JWT token request to work?

I'm building this API using JWT and NestJS. This is an API for a mobile application so I need the JWT Token to be constantly refreshed. The idea is to check the incoming token request, if the token is expired, JWT will thrown an error message saying…
MrRobot
  • 1,001
  • 1
  • 14
  • 34
0
votes
2 answers

TypeError: Cannot read property 'sign' of undefined [JWT / Nestjs / e2e tests]

I need to generate a Jwt Bearer Token for my e2e tests. As the process it a bit tedious, and because that's not what I am trying to test, I'd like to bypass it by directly getting instead of going through the 2FA real process. Unfortunately I keep…
A Mehmeto
  • 1,594
  • 3
  • 22
  • 37