You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
By default, if authentication fails, the AuthGuard will respond with a generic unauthorized error message.
But In some cases the built-in options are not sufficient to handle an authentication request.
Then it should be possible provide a Custom Callback to allow the application to handle success or failure.
For example:
constCustomCallback=(err,user,info)=>{letmessageif(err){returnPromise.reject(err||newUnauthorizedException());}elseif(typeofinfo!='undefined'||!user){switch(info.message){case'No auth token':
case'invalid signature':
case'jwt malformed':
case'invalid token':
message="You must provide a valid authenticated access token"breakcase'jwt expired':
message="Your session has expired. Please log in again"break}returnPromise.reject(newUnauthorizedException(message))}Promise.resolve(user);}
@Get('data')
@UseGuards(AuthGuard('jwt',{session: false},CustomCallback))getSensitiveData(){// this route is restricted}
The text was updated successfully, but these errors were encountered:
By default, if authentication fails, the AuthGuard will respond with a generic unauthorized error message.
But In some cases the built-in options are not sufficient to handle an authentication request.
Then it should be possible provide a Custom Callback to allow the application to handle success or failure.
For example:
The text was updated successfully, but these errors were encountered: