Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sentry does not trigger in AuthGuards' strategy #485

Open
bendadaniel opened this issue Nov 11, 2022 · 1 comment
Open

Sentry does not trigger in AuthGuards' strategy #485

bendadaniel opened this issue Nov 11, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@bendadaniel
Copy link

Hello,
my sentry implementation work fine except one situation.

I am using on controller's routes Auth guard with custom strategy @UseGuards(LocalAuthGuard)

LocalAuthGuard strategy is simple class (local.strategy.ts):

@Injectable()
export class LocalStrategy extends PassportStrategy(Strategy) {
    constructor(private authService: AuthService) {
        super();
    }
    async validate(username: string, password: string): Promise<User | false> 
    {        

        throw new Error("sentry test error");    //!!!!!!!!!!!!!!!!!!!!!!!!!!

        let user = await this.authService.validateUserByPassword(username, password);        
        if (!user) 
            return false;               
        return user;
    }
}

when I throw error in function validate(), setry will not catch it..

Do you know where could be problem or is it normal?

Thank you
Daniel

@mentos1386 mentos1386 added the bug Something isn't working label Nov 11, 2022
@mentos1386
Copy link
Owner

mentos1386 commented Nov 11, 2022

Hm, i think it's due to Guards being triggered before Interceptors[1]. We are using Interceptors to capture exceptions.

Not sure what the correct "fix" would be for this. Maybe we should introduce a "SentryExceptionFilter", which gets triggered by errors thrown in Guards[2].

[1] https://docs.nestjs.com/guards
[2] https://docs.nestjs.com/exception-filters

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants