authrm
v1.0.1
Published
An npm package for authentication
Downloads
2
Readme
AUTHRM
A npm
package for authentication.
Tech Stack
Server: Node
Requirements
Your user model
should contain atleast these points.
username: { type: String, required: true, unique: true },
email: { type: String, required: true, unique: true },
password: { type: String, required: true }
How to use?
Import
Import this package using npm i authrm
Configuration
authrm.config(userModel, tokenSecret, tokenExpiry);
userModel
: This is path to your user model.tokenSecret
: This is JWT token secret-key you want to set.tokenExpiry
: This is JWT token expiry time.
functionalities
- SignIn
authrm.signIn(req,res);
- This takes
req
andres
objects as a parameter. - This returns an object.
- If there are no errors occured then object contains
status code
asstatus
,user
which has been signed in or signed up,message
andjwt token
.
return { status, user, message, token };
- If there is error then object contains
status code
asstatus
anderror
which specifies the error.
return { status, error }
- If there are no errors occured then object contains
- SignUp
authrm.signUp(req,res);
- This also returns same objects as signIn.
- SignOut
authrm.signOut(req,res,tokenName);
This takes an extra parameter called
tokenName
which is the token you want to delete on signout function.This will return an object containing
status
andmessage
fields in case of no errors. And in case of errors it will return an object containingstatus
anderror
fields.
- Change password
authrm.changePassword(req,res);
- This checks weather user has entered correct current password.
- If yes then replaces the password and returns an object containing
status
,message
anduser
fields. - In case of error it returns an object containing
status
anderror
fields.