1.6 KiB

sidebar_position
sidebar_position
1

Login (Credentials)

This method allows you to create a auth session with a username and password.

:::info Use of server keys is recommended instead using credentials. :::

Parameters

Parameter Type Optional Default Description
payload Object true
callback Function false

[Object] Payload

Parameter Type Optional Default Description
username String true
password String true
mfa_code String false Required if MFA is enabled for this user

[Function] Callback

Executed on successful login

Parameter Type Content
data Object Successful Auth

[Object] Successful Auth

Contains the token and refresh token

Parameter Type Content
token String
refreshToken String
expires_in String

Examples

Basic usage

const auth = await AuthModel.login({
    username: "testuser",
    password: "testpassword",
})

console.log(auth)

// returns
// {
//    token: "xxxx",
//    refreshToken: "xxxx",
// }

Using Callback

AuthModel.login({
    username: "testuser",
    password: "testpassword",
}, (data) => {
    console.log(data)
    
    // returns
    // {
    //    token: "xxxx",
    //    refreshToken: "xxxx",
    // }
})