authrm
v1.0.1
Published
An npm package for authentication
Downloads
4
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
reqandresobjects as a parameter. - This returns an object.
- If there are no errors occured then object contains
status codeasstatus,userwhich has been signed in or signed up,messageandjwt token.
return { status, user, message, token };- If there is error then object contains
status codeasstatusanderrorwhich 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
tokenNamewhich is the token you want to delete on signout function.This will return an object containing
statusandmessagefields in case of no errors. And in case of errors it will return an object containingstatusanderrorfields.
- 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,messageanduserfields. - In case of error it returns an object containing
statusanderrorfields.
