nestjs / jwt

JWT utilities module based on the jsonwebtoken package 🔓

Home Page:https://nestjs.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How to handle a route that authentication is optional?

seekcx opened this issue · comments

commented

I'd like to create routes that authenticates req.user for authenticated users but still allow non authenticated users to access the route.

Would anybody be as kind to give me a workaround?

You can simply extend AuthGuard and return true even if canActivate either throws an exception/returns false. :)

@kamilmysliwiec Could you please attach passport info object to the exception that you throw, because I need to know why the exception was actually thrown.