Skip to content

yeldonkellie/mystical-mist-auth

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mystical-mist-auth

mystical-mist-auth is a simple authentication library for Node.js applications, providing user registration, login, authentication middleware, and protected route functionality using JSON Web Tokens (JWT).

Installation

You can install mystical-mist-auth via npm:

npm install mystical-mist-auth

Usage

const { authenticateToken, registerUser, loginUser, protectedRouteHandler } = require('mystical-mist-auth');

// Example usage:

// Register a new user
registerUser('exampleUser', 'examplePassword');

// Login a user and generate JWT token
const token = loginUser('exampleUser', 'examplePassword');

// Define a protected route
app.get('/protected-route', authenticateToken, protectedRouteHandler);

API

registerUser(username: string, password: string): void

Registers a new user with the provided username and password.

loginUser(username: string, password: string): string | null

Authenticates the user with the provided username and password. Returns a JWT token upon successful authentication, or null if authentication fails.

authenticateToken(req: Request, res: Response, next: NextFunction): void

Middleware function to authenticate JWT tokens for protected routes. It verifies the token included in the Authorization header of the incoming request.

protectedRouteHandler(req: Request, res: Response): void

Example handler for a protected route. It demonstrates how to use the authenticateToken middleware to protect routes and access the authenticated user's information via req.user.

Contributing

Contributions are welcome! Feel free to submit issues and pull requests.

License

This project is licensed under the MIT License - see the LICENSE file for details.

About

A library for authentication using Passport.js

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published