Questions tagged [nestjs-passport]

104 questions
19
votes
2 answers

how to get user data with req.user on decorator in nest js

I created the authentication ( jwt ) and the process is done properly. I can access the user's information using the following code, but I can't get the user's information using the decorator! controller : @Post('/me/info') …
moh
  • 205
  • 1
  • 3
  • 6
18
votes
3 answers

Get current user in nestjs on a route without an AuthGuard

I use nestjs with passport with jwt strategy. And I want to get a current user on some of my requests. Currently, I have a decorator that looks like this: import { createParamDecorator, ExecutionContext } from '@nestjs/common'; export const…
ZVER3D
  • 262
  • 1
  • 3
  • 10
16
votes
4 answers

NestJs Passport jwt unknown strategy

I am trying to implement a JWT strategy for authentication in my nest application. I am getting the following error tho Unknown authentication strategy "jwt" This is my code: jwt.strategy.ts import { Injectable } from "@nestjs/common"; import {…
Jan Krüger
  • 786
  • 1
  • 5
  • 16
13
votes
3 answers

NestJS custom PassportStrategy not registered when shared through library

I've been tasked with isolating our NestJS authentication module into a separate shared library, in order for it to be reused between multiple NestJS projects. Each project lives in each own repository and the shared library is imported as an npm…
Nikolaj Dam Larsen
  • 5,455
  • 4
  • 32
  • 45
11
votes
3 answers

Authorization in Nestjs using graphql

I have started to learn Nestjs, express and graphql. I encountered a problem while trying to authorize access of user authenticated using jwt token. I followed the tutorial for authentication on the Nestjs website. I am able to get the current user,…
Adriel
  • 183
  • 1
  • 2
  • 11
10
votes
1 answer

Extends the Request interface to add a fixed user property and extend any other class

I'm doing a server-side application with NestJS and TypeScript in combination with the implementation of Passport JWT. A little bit of context first: My JwtStrategy (no issues here): @Injectable() export class JwtStrategy extends…
RRGT19
  • 1,437
  • 3
  • 28
  • 54
9
votes
1 answer

PassportJS, NestJS: canActivate method of AuthGuard('jwt')

Does anybody know where I can see the full code of canActivate method in AuthGuard('jwt')? I realized that canActivate method calls JwtStrategy validate method by using console.log() like this: // jwt.strategy.ts @Injectable() export class…
9
votes
3 answers

Nest can't resolve dependencies of AuthService

I am following the documentation present here https://docs.nestjs.com/techniques/authentication#jwt-functionality To have faster support I have created a git repository with the problem https://github.com/Sano123456/nestjs-jwt node -v ->…
Sano
  • 469
  • 2
  • 6
  • 21
8
votes
3 answers

NestJS/GraphQL/Passport - getting unauthorised error from guard

I'm trying to follow along with this tutorial and I'm struggling to convert the implementation to GraphQL. local.strategy.ts @Injectable() export class LocalStrategy extends PassportStrategy(Strategy) { constructor(private readonly…
Ellie G
  • 239
  • 1
  • 4
  • 11
8
votes
3 answers

NestJS' Passport Local Strategy "validate" method never called

I'm trying to implement a Passport Local Strategy but the validate method is not working. When I do @UseGuards(AuthGuard("local")), it automatically throws an Unauthorized Exception without going through the validate method that I wrote. I have no…
7
votes
3 answers

How can I user configService in super()?

I have a question about setting environmental variables. In official document, it says using ConfigModule in this case, but my case is a exception case. Because I would like to use it in super() in constructor. My code is the below. Is there any…
shun
  • 71
  • 1
  • 2
7
votes
4 answers

Cannot find module 'passport' or its corresponding type declarations

I am using @nestjs/passport. After running npm run start:dev I got an error, but the editor doesn't show an error node_modules/@nestjs/passport/dist/passport/passport.serializer.d.ts:1:27 - error TS2307: Cannot find module 'passport' or its…
PrabodhanaJ
  • 263
  • 1
  • 4
  • 12
6
votes
6 answers

NestJs JWT Authentication returns 401

I have implemented a jwt authentication in nestJs. However whenever I attempt to authenticate using the following authorization headers: Bearer or JWT I got 401. These are my authentication files @Injectable() export class…
Arsene
  • 1,037
  • 4
  • 20
  • 47
6
votes
7 answers

NestJS jwt-passport Authentication

I want to implement a distributed authentication library to use it on several projects. The library should implement JWT authentication method. The code is as follows: jwt.strategy.ts import {ExtractJwt, Strategy} from 'passport-jwt'; import…
CountZero
  • 186
  • 1
  • 1
  • 8
5
votes
0 answers

nestjs invalid algorithm error with bearer token from google

I'm trying to secure a nestjs api project using a jwt generated by google oauth. I have the client code working and have verified with jwt.io that the jwt being generated is correct and validates ok with the client secret I have. I have followed the…
ciantrius
  • 683
  • 1
  • 6
  • 21
1
2 3 4 5 6 7