kowsik-simple-auth
v1.0.3
Published
A simple authentication library
Downloads
3
Readme
Simple Auth
Simple Auth is a lightweight Node.js package for generating and verifying JWT (JSON Web Token) tokens for authentication purposes. It also provides an Express middleware for verifying tokens in routes that require authentication.
Installation
You can install Simple Auth via npm:
npm install simple-auth
Usage
// Generate access token
const accessToken = generateAccessToken(userData, jwtSecret, jwtExpiresIn);
console.log("Access Token:", accessToken);
// Generate refresh token
const refreshToken = generateRefreshToken(userData, jwtSecret);
console.log("Refresh Token:", refreshToken);
generateAccessToken(data, secret, expiresIn)
Generates an access token using the provided data, secret, and expiration time.
const accessToken = generateAccessToken(userData, jwtSecret, jwtExpiresIn);
generateRefreshToken(data, secret)
Generates a refresh token using the provided data and secret.
const refreshToken = generateRefreshToken(userData, jwtSecret);
verifyAccessToken(token, secret)
Verifies the validity of an access token.
const verifiedData = verifyAccessToken(accessToken, jwtSecret);
if (verifiedData) {
console.log("Access Token Verified:", verifiedData);
} else {
console.log("Access Token Verification Failed");
}
verifyToken(req, res, next)
Express middleware for verifying JWT tokens in routes that require authentication.
app.get("/protected-route", verifyToken, (req, res) => {
res.json({ message: "Authenticated!", user: req.user });
});
License
This package is licensed under the MIT License.