firebase-auth-node
v1.0.3
Published
A firebase auth for backend node
Downloads
4
Maintainers
Readme
firebase-auth-node
simple firebase auth for backend node
Features
- super easy API for signing in with email/password
- Get the id token of the user that signed in
Install
npm install firebase-auth-node
Requirements
Go to https://firebase.google.com/ and create a project
Get the firebase config for NodeJS and save as a JSON file, guide here https://firebase.google.com/docs/web/setup
{
"apiKey": "",
"authDomain": "",
"projectId": ""
}
- Get the service key of your firebase project and save as a JSON file, guide here https://firebase.google.com/docs/admin/setup#add_firebase_to_your_app
{
"type": "",
"project_id": "",
"private_key_id": "",
"private_key": "",
"client_email": "",
"client_id": "",
"auth_uri": "",
"token_uri": "",
"auth_provider_x509_cert_url": "",
"client_x509_cert_url": ""
}
Open up authentication for your project and add sign in method email/password
Add an account to the authentication
Usage
let serviceKey = require('./firebase-config/firebase.service-key.json'); // The service key of the firebase project
let firebaseConfig = require('./firebase-config/firebase.config.json'); // The config for the firebase project
let FirebaseAuthNode = require('firebase-auth-node');
let firebaseAuth = new FirebaseAuthNode(firebaseConfig, serviceKey)
API
firebaseAuth = new FirebaseAuthNode(firebaseConfig, serviceKey, nameOfAdmin)
Initialize the firebase config and service key to firebase and firebase-admin.
nameOfAdmin is optional and is used if you have multiple instances of firebase admin.
firebaseAuth.signIn(email, password)
Tries to sign with the provided email and password, if success it will return an object with the idToken and uid of the user. The type of email
and password
is string, if not an error is thrown. This function returns a Promise that you need to handle.
firebaseAuth.authToken(idToken)
Uses firebase-admin to check if the id token of an user you provide is an valid token. The type of idToken
is string, if not an error is thrown. This function returns a Promise that you need to handle.