Skip to main content

Class: AuthService

Service responsible for handling authentication-related operations.

Description

The AuthService provides functionality for:

  • User validation during sign-in
  • User registration (sign-up)
  • JWT token generation and management

It integrates with:

  • DrizzleService for database operations
  • HashingService for password encryption
  • JwtService for token management
  • UsersService for user-related operations

Constructors

new AuthService()

new AuthService(drizzleService, hashingService, configService, jwtService, userService): AuthService

Parameters

drizzleService

DrizzleService

hashingService

HashingService

configService

ConfigService

jwtService

JwtService

userService

UsersService

Returns

AuthService

Methods

validateUser()

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

Validates user credentials during sign-in.

Parameters

login

string

The user's email or username

password

string

The user's password (plain text)

Returns

Promise<InferSelectModel<any>>

Promise resolving to the validated User object

Throws

BadRequestException if credentials are invalid


signUp()

signUp(signUpDto): Promise<any>

Registers a new user in the system.

Parameters

signUpDto

SignUpDto

Data transfer object containing user registration details

Returns

Promise<any>

Promise resolving to the newly created user

Throws

BadRequestException if email is already in use


generateTokens()

generateTokens(userId): Promise<{ accessToken: any; }>

Generates authentication tokens for a user.

Parameters

userId

string

The ID of the user to generate tokens for

Returns

Promise<{ accessToken: any; }>

Promise resolving to an object containing the access token

Throws

Error if user is not found