identifiQ
A package for handling IdentifiQ API interactions.
This package provides a set of methods for interacting with the IdentifiQ API, enabling users to register, log in, retrieve user data, and manage password changes. It's designed to make it easier to integrate authentication and user management features into Node.js applications.
IdentifiQ Usage Requirements
When using IdentifiQ systems, it is important to mention that the connection is made via IdentifiQ. Additionally, you must include one of the official IdentifiQ logos, as shown below, without modifying its color.
Installation
To install the identifiQ
package, run the following command:
npm install identifiq
Usage
Importing the Package
const identifiQ = require('identifiq');
Creating an Instance
To interact with the IdentifiQ API, you need to create an instance of the identifiQ
class. Pass your client identifier to the constructor:
const clientKey = 'your-client-key'; // Replace with your client identifier
const api = new identifiQ({ client: clientKey });
Registering a New User
To register a new user, call the register
method and provide the required username
, email
, and password
:
api.register({ username: 'user123', email: 'user@example.com', password: 'securepassword' })
.then(response => {
console.log(response);
})
.catch(error => {
console.error('Registration error', error);
});
Logging In a User
To log a user in, call the login
method with the email
, password
, and optionally an expiresIn
parameter (default is 1d
):
api.login({ email: 'user@example.com', password: 'securepassword', expiresIn: '1d' })
.then(response => {
console.log(response); // Returns a message and an access token to the user's data
})
.catch(error => {
console.error('Login error', error);
});
Retrieving User Data
To retrieve user data, call the getUserData
method with a valid token
:
const token = 'user-auth-token'; // Replace with a valid token
api.getUserData({ token })
.then(response => {
console.log('User data:', response);
})
.catch(error => {
console.error('Error retrieving user data', error);
});
Requesting a Password Change
If the user needs to reset their password, call the requestPasswordChange
method with the email
and optional emailDetails
(such as custom messages):
api.requestPasswordChange({
email: 'user@example.com',
emailDetails: {
subject: "Request to reset password",
html: "Your reset password code is: <strong>{code}</strong>"
}
})
.then(response => {
console.log('Password change request successful', response);
})
.catch(error => {
console.error('Password change request error', error);
});
Changing Password
Once the user has received a password change code, they can use it to change their password by calling the changePassword
method:
api.changePassword({ code: 'reset-code', newPassword: 'newsecurepassword' })
.then(response => {
console.log('Password change successful', response);
})
.catch(error => {
console.error('Password change error', error);
});
Methods
register({ username, email, password })
- Description: Registers a new user.
- Parameters:
username
(String): The username of the new user.email
(String): The email of the new user.password
(String): The password for the new user.
- Returns: A promise that resolves to the API response or an error object.
login({ email, password, expiresIn = '1d' })
- Description: Logs in a user and retrieves a token.
- Parameters:
email
(String): The user's email.password
(String): The user's password.expiresIn
(String, optional): The expiration time for the token in formatnumber[hmds]
(default is1d
).
- Returns: A promise that resolves to the API response or an error object.
getUserData({ token })
- Description: Retrieves the authenticated user's data.
- Parameters:
token
(String): The authentication token.
- Returns: A promise that resolves to the API response or an error object.
requestPasswordChange({ email, emailDetails: { subject, html } })
- Description: Requests a password change for the user.
- Parameters:
email
(String): The user's email.emailDetails
(Object [subject, html], optional): Details for the email message.
- Returns: A promise that resolves to the API response or an error object.
Tag | Description | Use in |
---|---|---|
{user} |
It is replaced by the username. | Subject, Html |
{client} |
It is replaced by the Client name (Your system registered in IdentifiQ). | Subject, Html |
{code} |
It is used to insert the user's code for password reset. | Html |
----- |
changePassword({ code, newPassword })
- Description: Changes the user's password.
- Parameters:
code
(String): The code received for changing the password.newPassword
(String): The new password.
- Returns: A promise that resolves to the API response or an error object.
Error Handling
The package handles errors by returning an error object with the following structure:
{
"success": false,
"status": 500,
"statusText": "Internal Server Error",
"message": "Error message from API or fallback message"
}
Success Handling
A copy of successful manipulations is logged to the console if logDataMessages
is set to true
during package instantiation.
License
This package is licensed under the Attribution 4.0 International License. See the LICENSE file for details.
Notes:
- The package uses axios for making HTTP requests to the IdentifiQ API.
- Ensure you have a valid client identifier to use the API.