npm i commondev-auth
const { CommondevAuth } = require('commondev-auth');
// or
import { CommondevAuth } from 'commondev-auth';
This method takes as input email. Sends 4-digit code to the specified email. This code expires in 5 minutes, to resend code use CommondevAuth.resendCode.
const registerRequest = await CommondevAuth.register({
email: 'example@gmail.com'
});
This method returns next step of authorization. For example:
{
error: null,
data: { next: "complete" },
}
This method takes as input email and code.
const completeRequest = await CommondevAuth.complete({
email: 'example@gmail.com'
code: 4232
});
This method returns authorization token. For example:
{
error: null,
data: { token: "EXAMPLE_TOKEN" },
}
This method takes as input email. Sends 4-digit code to the specified email. This code expires in 5 minutes, to resend code use CommondevAuth.resendCode.
const loginRequest = await CommondevAuth.login({
email: 'example@gmail.com'
});
This method returns next step of authorization. For example:
{
error: null,
data: { next: "complete" },
}
This method takes as input jwt token that you can get via CommondevAuth.complete.
const getUserDataRequest = await CommondevAuth.getUserByToken({
token: 'TOKEN',
});
This method returns user data. For example:
{
"error": null,
"data": {
"user": {
"created": "2023-06-18T14:46:55.307Z",
"email": "example@gmail.com",
"token": "EXAMPLE_TOKEN"
}
}
}
This method takes as input email. Sends 4-digit code to the specified email. This code expires in 5 minutes, to resend code use CommondevAuth.resendCode.
const resendCodeRequest = await CommondevAuth.resendCode({
email: 'example@gmail.com'
});
This method returns next step of authorization. For example:
{
error: null,
data: { next: "complete" },
}