Skip to main content
Nest @nestjs/passport wraps Node passport strategies. nestrs already has AuthStrategy and AuthStrategyGuard. nestrs-auth-strategy ships the two strategies apps reach for first: JWT bearer and HTTP Basic (a passport-local analogue when the password rides in Authorization, not a JSON body). PassportGuard is a re-export of nestrs_security::AuthStrategyGuard.

Install

JwtStrategy

JwtStrategy::new receives the raw bearer token (not a parsed JWT). Verify it in the closure (jsonwebtoken, JWKS, opaque lookup). PassportGuard<S> requires S: AuthStrategy + Default. Wrap the closure strategy in a Default type you can put on #[use_guards]:
Replace the token.is_empty() check with real JWT verification.

LocalBasicStrategy

Parses Authorization: Basic base64(user:pass) and calls validate(username, password):
Body-based local login still belongs in a handler. AuthStrategy only sees request parts.

Compared with OAuth2Guard

Use OAuth2 when you already have an issuer and JWKS. Use Passport strategies for custom bearer checks or HTTP Basic. See the security guide for AuthStrategyGuard and the OAuth2 guide for JWKS.