authatez-custom
v1.0.2
Published
auth made ez, but inject your db
Downloads
2
Maintainers
Readme
AuthAtEz
AuthatEz is a simple, minimalistic authenticator that you can use on your applications.
Features
- User registration with hashed password storage.
- User login with password comparison.
- Redirect URLs for successful registration and login.
- Custom callbacks for registration and login events.
- Middleware setup for handling authentication pages and requests.
- Connects to external mongoDB database
Non-Features
- no two step authentication (sorry)
- no email authentication
Installation
First install dependencies, you may not need to do this if npm does its job-
npm install express mongoose bcrypt path
npm install authatez-custom
dotenv is already setup in the module, so no need to do that nasty stuff
Usage
all you need is 3 lines of code (for the class atleast):
Require
const { AuthAtEz } = require("authatez-custom");
Setup
const main = async () => {
//...
const auth = new AuthAtEz(process.env.CONNECTION_STRING, "database_name", "/registration_redirect", "/login_redirect", Registration_Callback, Login_Callback); //note the callbacks get 2 params (email, password)
app.use(auth.app); //in-order for the class's express to connect to your express
//...
}
main().catch((err) => {
console.error("Error starting server:", err);
});
Dependencies
- express
- path
- bcrypt
- mongoose
Example
const { AuthAtEz } = require("authatez-custom");
require("dotenv").config();
const express = require("express");
const main = async () => {
const app = express();
const port = 3000;
const handleReg = (email, password) => {
app.get("/kyoto", (req, res) => {
res.send(`Registered with email: ${email} and password: ${password}`);
});
};
const handleLog = (email, password) => {
app.get("/tokyo", (req, res) => {
res.send(`Logged in with email: ${email} and password: ${password}`);
});
};
const auth = new AuthAtEz(process.env.CONNECTION_STRING, "sukunabarbershop", "/kyoto", "/tokyo", handleReg, handleLog);
//yes i am a jjk fan, got a problem?
app.use(auth.app);
app.listen(port, () => {
console.log(`Server is running on http://localhost:${port}`);
});
};
main().catch((err) => {
console.error("Error starting server:", err);
});