1.0.3 • Published 10 months ago

fireauth-wrapper v1.0.3

Weekly downloads
-
License
MIT
Repository
-
Last release
10 months ago

firebase-auth-wrapper

A robust and flexible authentication and authorization solution for Express.js applications using Firebase.

Description

Firebase Auth Wrapper simplifies the process of implementing secure authentication and fine-grained authorization in your Express.js applications. By leveraging Firebase Authentication and providing a powerful policy-based authorization system, this package allows you to easily protect your routes and enforce access controls.

Key Features

  • Seamless integration with Firebase Authentication
  • Policy-based authorization system
  • Support for role-based access control (RBAC)
  • Tag-based permissions for flexible access management
  • Easy-to-use middleware for Express.js routes
  • TypeScript support for enhanced developer experience

Installation

npm install firebase-auth-wrapper

Usage

import express from 'express';
import { Authentication } from 'firebase-auth-wrapper';
import admin from 'firebase-admin';
import mongoose from 'mongoose';

const app = express();

// Initialize Firebase Admin SDK
admin.initializeApp();

// Create an instance of the Authentication class
const auth = new Authentication(req, res, next, admin);

// Use the authentication middleware
app.use(auth.authenticate());

// Protect a route with authentication and authorization
app.get('/protected-route', auth.authorize(User, [{
  role: "Admin",
  user: new mongoose.Types.ObjectId("user_id_here")
}]), (req, res) => {
  res.send('Access granted to protected route');
});

app.listen(3000, () => console.log('Server running on port 3000'));

Documentation

For detailed usage instructions and API documentation, please refer to our GitHub repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License.