node_auth_module v1.2.2
node_auth_module
Authentication module using node_db_module
This uses the sequelize framework to provide an authentication frameowork to integrate with your application, using supported SQL OSBDs.
Import the db schema
mysql -u [user] -D [database] -p < sql/schema.sql
Configure credentials
The basic credentials structure is the following. They can be setup as a file in the root that is passed on when instancing the module. You can also send the JSON directly if you are storing the varibles as ENV variables. Ex: (...),password:proccess.env.PASSWORD,(...)
{
"sql": {
"host":"127.0.0.1",
"database":"yourdatabasename",
"username":"yourusername",
"password":"yourpassword",
"dialect":"mysql",
"logging":false,
"timezone":"+00:00"
},
"seedDB":false,
"seedMongoDB":false,
"seedDBForce":true,
"db":"sql"
}
Simple example
const Auth = require('node_auth_module')
const authModule=new Auth(".config_auth.js")
- .config_auth.js is the JSON file with the credentials this file should be in the root of your app. (Not of this required module) Then run one of the following functions
Authentication
register
- type: async function
parameters: firstName,lastName,email,password,thirdparty
- firstName (string)
- lastName (string)
- email (string)
- password (sring)
- thirdparty (boolean) optional
returns id (int)
- The primary key (id) of the table User
return error
- if there is some problem
Usage:
authModule.auth.register(firstName,lastName,email,password,thirdparty)
activateUser
- type: async function
parameters: id
- id (int)
returns ??
- db model with update result
return error
- if there is some problem (it should at least)
Usage:
authModule.auth.activateUser(id)
inactivateUser
banUser
unbanUser
isBanned
isActive
resetpassword
resetpassword(id)
- type:asycn function
Returns: new password
validateLogin
validateLogin(email,password,callback,req,res)
- type:async function
- Returns: What every happens in the callback function. Generally used to set alternative response in case of error in callback. {action,path,payload}
getUserInfo
getUserMetadata
getIdFromEmail
hashPassword
listUsers
validateEmailConfirmationToken
validateEmailConfirmationToken(email,confirmationToken)
- Validates the confirmation token belongs to the email user
- parameters: email, confirmationToken
- Returns: boolean ###setNewConfirmationToken
setNewConfirmationToken(id)
Generates a new confirmation token and stores it for the user.
- Returns confirmation token
Session
saveSession
- type: async function
parameters: user_id,ipv4,ipv6,platform,valid,city,country
- user_id (int)
- ipv4 (string)
- ipv6 (string)
- platform (sring)
- valid (boolean)
- city (string)
- country (string)
returns id
- if all goes well
return error
- if there is some problem
Usage:
authModule.session.saveSession(user_id,ipv4,ipv6,platform,valid,city,country)
listSessions
- type: async function
parameters: userId
- userId (int) Primary key (id) from table Person
returns (array)
- List of all the session for the userId, the accessToken will not be present in the array
Usage:
authModule.session.listSessions(userId)
revokeSession
- type: async function
parameters: id
- id (int)
returns ??
- update result
Usage:
authModule.session.revokeSession(id)
validateSession
- type: async function
parameters: id,accessToken
- id (int)
- accessToken (string)
returns (boolean)
- Valid or Not
Usage:
authModule.session.validateSession(id,accessToken)
12 months ago
12 months ago
12 months ago
12 months ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
1 year ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago