rawfishindustries-firebase-auth
v2.0.1
Published
Firebase authentication and push notification package
Downloads
68
Readme
Firebase Service Wrapper
Firebase Service is a Node.js library designed to simplify Firebase integration in Express.js application. It provides a class to easily integrate Firebase singleton. Then a Base service and two integrations for auth and notification complete the library.
Installation
npm install rawfishindustries-firebase-authUsage
Importing and initialize library
import AuthService from 'rawfishindustries-firebase-auth';
// Initialize an instance of FirebaseInstance
FirebaseInstance.initialize(
'your-firebase-project-id',
'your-firebase-client-email',
'your-firebase-private-key',
true, // Enable caching (default is true)
{ host: 'your-redis-host', port: 6379 }, // Redis connection parameters
'your-firebase-database-url', // Optional: Firebase database URL
);
const authService = FirebaseInstance.getAuth();Middleware usage
// Use the middleware in your Express route
app.get('/protected-route', authService.verifyMiddleware, (req, res) => {
// Access protected resources here
res.send('Authenticated user!');
});Notification usage
const notification = FirebaseInstance.getNotification();
await notification.sendPushNotification('PUSH_TOKEN', 'Message title', 'Message body', { someData: 'Data' });Custom service
You can create your own custom service using the built-in singleton Firebase integration.
export default class FirebaseExampleService extends FirebaseBaseService {
constructor(instance: FirebaseInstance) {
super(instance);
}
public async example(param: string): Promise<string> {
return await this.firebaseInstance.app...
}
}Configuration options
- projectId (string): The ID of your Firebase project.
- clientEmail (string): The client email associated with your Firebase project.
- privateKey (string): The private key associated with your Firebase project.
- enableCache (boolean, optional): Whether to enable caching. Defaults to true.
- redisConnection (RedisConnection): The connection parameters for Redis.
- databaseUrl (string, optional): The URL of your Firebase Realtime Database.
Features
- Firebase Authentication: Automatically verifies Firebase authentication tokens.
- Caching: Optionally cache decoded tokens in Redis to reduce the load on Firebase servers.
- Middleware: Easily integrate the middleware into your Express routes for authentication.
- Notification service: A simple message builder for Firebase
- Base service: An extendible class to create a Firebase service using singleton.
License
This library is licensed under the MIT License.
