firebase-login-email
v0.4.0
Published
This package is a wrapper to Firebase simple login including all dependencies with the exception of firebase it self. Authenticate your Firebase using your Firebase simple login credentials.
Maintainers
Readme
firebase-login-email
Authenticating Users with Email & Password
Firebase makes it easy to integrate email and password authentication into your app. Firebase automatically stores your users' credentials securely (using bcrypt) and redundantly (daily off-site backups).
This separates sensitive user credentials from your application data, and lets you focus on the user interface and experience for your app. Allows your node applications to authenticate a Firebase reference using Firebase Simple Login with email and password.
Important
:heavy_exclamation_mark: Do not embet your credentials on public code!
Installation
Install via npm:
npm install firebase firebase-login-emailExample
const { initializeApp } = require('firebase/app');
require('firebase/auth');
const FirebaseLoginEmail = require('firebase-login-email');
const app = initializeApp({
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
});
new FirebaseLoginEmail(
app,
{
email: process.env.FIREBASE_EMAIL,
password: process.env.FIREBASE_PASSWORD,
},
(error, user) => {
if (error) {
console.error('Login failed:', error.message);
return;
}
console.log('Logged in as:', user.uid);
}
);Promise-based (async/await):
const { initializeApp } = require('firebase/app');
const { FirebaseLoginEmail } = require('firebase-login-email');
const app = initializeApp({
apiKey: process.env.FIREBASE_API_KEY,
authDomain: process.env.FIREBASE_AUTH_DOMAIN,
});
const user = await FirebaseLoginEmail.login(app, {
email: process.env.FIREBASE_EMAIL,
password: process.env.FIREBASE_PASSWORD,
});
console.log('Logged in as:', user.uid);Load credentials from a .env file (e.g. with dotenv) or set FIREBASE_API_KEY, FIREBASE_AUTH_DOMAIN, FIREBASE_EMAIL, and FIREBASE_PASSWORD in your environment before running.
Sign up (create account)
const user = await FirebaseLoginEmail.signUp(app, {
email: process.env.FIREBASE_EMAIL,
password: process.env.FIREBASE_PASSWORD,
});
console.log('Created user:', user.uid);Password reset
await FirebaseLoginEmail.sendPasswordReset(app, '[email protected]');
// User receives an email with a reset linkAuth state (react to sign-in / sign-out)
const unsubscribe = FirebaseLoginEmail.onAuthStateChanged(app, (user) => {
if (user) console.log('Signed in:', user.uid);
else console.log('Signed out');
});
// Later: unsubscribe() to stop listeningID token (for your backend)
const { user, idToken } = await FirebaseLoginEmail.loginWithIdToken(app, {
email: process.env.FIREBASE_EMAIL,
password: process.env.FIREBASE_PASSWORD,
});
// Send idToken in Authorization header: Bearer <idToken>
// Or get token from an already signed-in user:
const token = await FirebaseLoginEmail.getIdToken(user);Support
Please report issues to the ticket system.
Contributing
See CONTRIBUTING.md for how to contribute, run tests, and install the project locally.
Thanks to
- A special thanks to the developers of NodeJS and Firebase.

