Class SecureAuthService

Injectable service that provides authentication-related functionalities, such as login, signup, password reset, and token validation.

Name

SecureAuthService

Hierarchy

  • SecureAuthService

Constructors

  • Creates an instance of the SecureAuthService.

    Parameters

    • prisma: PrismaService

      Instance of the PrismaService to interact with the database.

    • configService: ConfigService<AuthConfigure, false>

      Instance of the ConfigService to access the authentication configuration.

    • jwtService: JwtService

      Instance of the JwtService to sign and verify JWT tokens.

    • mailService: MailService

      Instance of the MailService to send emails.

    Returns SecureAuthService

Properties

configService: ConfigService<AuthConfigure, false>

Instance of the ConfigService to access the authentication configuration.

emailTransporterConfig: {
    auth: {
        pass: string;
        user: string;
    };
    host: string;
    port: number;
    secure: boolean;
    sender: string;
}

Configuration object for the email transporter used for sending emails.

Type declaration

  • auth: {
        pass: string;
        user: string;
    }

    Authentication credentials for the email server.

    • pass: string

      The password used for authenticating with the email server.

    • user: string

      The username used for authenticating with the email server.

  • host: string

    The hostname of the email server.

  • port: number

    The port number of the email server.

  • secure: boolean

    A boolean indicating if the connection to the email server should use SSL/TLS.

  • sender: string

    The email address of the sender.

forgotPasswordConfig: {
    resetPasswordExpiration: number;
    resetPasswordUrl: string;
}

Configuration object for the "Forgot Password" functionality.

Type declaration

  • resetPasswordExpiration: number

    The expiration time (in milliseconds) for the reset token.

  • resetPasswordUrl: string

    The URL where users will be redirected to reset their password.

jwtService: JwtService

Instance of the JwtService to sign and verify JWT tokens.

mailService: MailService

Instance of the MailService to send emails.

Instance of the PrismaService to interact with the database.

transporter: Transporter<any>

Nodemailer transporter used to send emails.

Methods

  • Finds or creates a user based on the provided OAuth profile.

    Parameters

    • profile: OAuthProfile

      The OAuth profile of the user.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        email: string;
        id: number;
        password: string;
        resetToken: string;
        resetTokenExpiration: Date;
        updatedAt: Date;
    }, unknown> & {}>

    • The existing or newly created user.

    Async

    Throws

    • If the user is not found based on the OAuth profile.
  • Initiates the "Forgot Password" flow for a user based on the provided email.

    Parameters

    • email: string

      The email of the user.

    Returns Promise<void>

    • A promise that resolves once the reset password email is sent.

    Async

    Throws

    • If an error occurs while sending the reset password email.
  • Checks if a password meets the required strength criteria.

    Parameters

    • password: string

      The password to check.

    Returns boolean

    • true if the password is strong; otherwise, false.
  • Authenticates a user based on their email and password and returns an access token upon successful authentication.

    Parameters

    • email: string

      The email of the user.

    • password: string

      The password of the user.

    Returns Promise<{
        access_token: string;
    }>

    • An object containing the access token.

    Async

    Throws

    • If the email or password is invalid.
  • Resets the password of a user based on the provided email and a new password.

    Parameters

    • userId: number
    • oldPassword: string

      The email of the user.

    • newPassword: string

      The new password for the user.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        email: string;
        id: number;
        password: string;
        resetToken: string;
        resetTokenExpiration: Date;
        updatedAt: Date;
    }, unknown> & {}>

    • The updated user object.

    Async

    Throws

    • If the user is not found.
  • Sends a reset password email to the user with a reset URL.

    Parameters

    • email: string

      The email of the user.

    • resetUrl: string

      The URL where the user can reset their password.

    Returns Promise<void>

    • A promise that resolves once the email is sent.

    Async

    Throws

    • If an error occurs while sending the email.
  • Registers a new user with the provided email and password.

    Parameters

    • email: string

      The email of the new user.

    • password: string

      The password of the new user.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        email: string;
        id: number;
        password: string;
        resetToken: string;
        resetTokenExpiration: Date;
        updatedAt: Date;
    }, unknown> & {}>

    • The newly created user.

    Async

    Throws

    • If the email is already associated with an existing user.
  • Stores the reset token and its expiration time in the user's database record.

    Parameters

    • email: string

      The email of the user.

    • resetToken: string

      The reset token to store.

    • expiration: number

      The expiration time of the reset token.

    Returns Promise<void>

    • A promise that resolves once the token is stored.

    Async

  • Validates the payload of a JWT token and retrieves the associated user from the database.

    Parameters

    • payload: TokenPayload

      The decoded payload of the JWT token.

    Returns Promise<GetResult<{
        createdAt: Date;
        deletedAt: Date;
        email: string;
        id: number;
        password: string;
        resetToken: string;
        resetTokenExpiration: Date;
        updatedAt: Date;
    }, unknown> & {}>

    • The user associated with the payload if valid.

    Async

    Throws

    • If the token is invalid or the user is not found.

Generated using TypeDoc