Constructor
new AuthService(setup)
Creates an instance of AuthService.
Parameters:
| Name | Type | Description | ||||||
|---|---|---|---|---|---|---|---|---|
setup |
Object | The setup object containing optional parameters. Properties
|
- Source:
Members
secretKey :string
Gets the secret key for generating JWT tokens.
Type:
- string
- Source:
userUID :string|undefined
Gets the user's unique identifier.
Type:
- string | undefined
- Source:
Methods
(async) createHash(password, saltLengthopt) → {string}
Creates a password hash using the provided password and salt length.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
password |
string | The password to be hashed. |
||
saltLength |
number |
<optional> |
8 | The length of the salt for password hashing. |
- Source:
Returns:
The hashed password.
- Type
- string
(async) createSessionCLI() → {void}
Creates a session for the Command-Line Interface (CLI) user.
- Source:
Throws:
-
If an error occurs during session creation.
- Type
- Error.Log
Returns:
- Type
- void
createUserToken() → {string}
Creates a JWT token for the user.
- Source:
Returns:
The generated JWT token.
- Type
- string
(async) dropSessionCLI(token) → {void}
Drops a session for the Command-Line Interface (CLI) user.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
string | The JWT token representing the session to be dropped. |
- Source:
Throws:
-
If an error occurs during session dropping.
- Type
- Error.Log
Returns:
- Type
- void
(async) genSalt(lengthopt) → {string}
Generates a salt for password hashing.
Parameters:
| Name | Type | Attributes | Default | Description |
|---|---|---|---|---|
length |
number |
<optional> |
8 | The length of the generated salt. |
- Source:
Returns:
The generated salt.
- Type
- string
genToken(data) → {string}
Generates a JWT token based on the provided data.
Parameters:
| Name | Type | Description |
|---|---|---|
data |
Object | The data to be encoded into the JWT token. |
- Source:
Returns:
The generated JWT token.
- Type
- string
(async) signIn(password) → {Success|Error.Log}
Validates user credentials and signs in the user.
Parameters:
| Name | Type | Description |
|---|---|---|
password |
string | The user's password to be validated. |
- Source:
Returns:
A Success object if authentication is successful, or an Error.Log object if authentication fails.
- Type
- Success | Error.Log
(async) signOut(token) → {boolean}
Signs out the user and deletes the corresponding session.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
string | The JWT token representing the user's session. |
- Source:
Throws:
-
If an error occurs during sign-out.
- Type
- Error.Log
Returns:
True if the session is successfully deleted, false otherwise.
- Type
- boolean
(async) validateCredentials(password) → {boolean}
Validates user credentials against the stored password hash.
Parameters:
| Name | Type | Description |
|---|---|---|
password |
string | The user's input password to be validated. |
- Source:
Returns:
True if the password matches the stored hash, false otherwise.
- Type
- boolean
validateToken(token) → {Object}
Validates a JWT token.
Parameters:
| Name | Type | Description |
|---|---|---|
token |
string | The JWT token to be validated. |
- Source:
Throws:
-
If the token validation fails.
- Type
- Error.Log
Returns:
The decoded data from the validated JWT token.
- Type
- Object