Skip to main content

Class: LocalStrategy

Local authentication strategy for Passport.

Description

This strategy implements username/password (local) authentication. It is used primarily for the initial user login process.

Configuration:

  • Uses 'login' field instead of default 'username' field
  • Integrates with AuthService for user validation

Example

// Route using local authentication
@UseGuards(LocalAuthGuard)
@Post('login')
async login(@Request() req) {
return this.authService.login(req.user);
}

Extends

  • any

Constructors

new LocalStrategy()

new LocalStrategy(authService): LocalStrategy

Configures the local strategy with custom field names.

Parameters

authService

AuthService

Service handling user authentication

Returns

LocalStrategy

Overrides

PassportStrategy(Strategy).constructor

Methods

validate()

validate(login, password): Promise<InferSelectModel<any>>

Validates user credentials against the database.

Parameters

login

string

The user's login (email or username)

password

string

The user's password

Returns

Promise<InferSelectModel<any>>

Promise resolving to the authenticated user

Throws

BadRequestException if credentials are invalid