This plugin gives you access to all authentication features. It can be used in another plugin to authorize your routes, but it also provides routes for login and registration.
Using Authentication
Here is how you can require authentication on a route.
Install the plugin:
yarn add cl_auth –registry http://localhost:4873
or if you are using NPM
npm i cl_auth –registry http://localhost:4873
Import the middleware:
Currently, only basic_auth
middleware is available.
var { basicAuth } = require("cl_auth");
router.use(basicAuth);
router.get("/authorizedRoute", authorizedAction);
End Points
Auth (/auth)
Manages the authentication operations like login, register, etc.
Title | /login |
Method | POST |
URL | POST /auth/login |
Description | Attempts to login using the provided username or password, returns the current user with authentication token if success, status code 400 otherwise. |
Body Parameters (POST only) | { data: { username: String (The username or email of the user). password: String (The plaintext password of user). rememberMe: String? (Whether to remember the user for seven days, remove it to remember for one day only). } } |
Query Parameters | |
Response | Status Code: 200 { token: String (The authentication token to use for authorization header) user: { username: String email: String password: String (hashed) } } Status Code: 400 (Failed to login) { message: String (The error message) } |
Requires Auth | NO |
Title | /authenticate |
Method | POST |
URL | Check if a user is logged in and auth token is valid, return the result and user if success. |
Description | Check if a user is logged in and auth token is valid, return the result and user if successful. |
Body Parameters (POST only) | Check if a user is logged in and auth token is valid, returns the result and user if successful. |
Query Parameters | |
Response | Status Code: 200 { success: true user: { username: String email: String password: String (hashed) } } Status Code: 400 (Failed to login) { message: String (The error message) } |
Requires Auth | YES |