Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

node-fireuser

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

node-fireuser

A user-management system for firestore & realtime database

  • 0.0.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

node-fireuser

This is a library for easy user management with Firebase Realtime Database and Firestore.

Installation and Initialization

Install the library easily with npm.

npm install node-fireuser 

You'll also need the Firebase-admin SDK for this library. Just install it aswell with npm.

npm install firebase-admin

After you installed both, you have to include them and do the first commands. If you don't know how to initialize the Firebase Admin SDK look here

With Webpack

import * as fireuser from ('node-fireuser')
import * as admin from ('firebase-admin')
import * as serviceWorker from ('path/to/your/json/file');

/* Initialize Firebase Admin
   It's necassary to do this BEFORE you init the Fireuser library
*/
admin.initializeApp({
    credential: admin.credential.cert(serviceWorker),
    databaseURL: "https://[YOUR PROJECT].firebaseio.com/"
});

/* Init Fireuser
   Use the firebase-admin variable as argument! In this case it's admin
*/
if(fireuser.init(admin)){
    console.log("Everything fine");
    ...
}else{
    console.log("An error appeared");
}

Without Webpack

const fireuser = require('node-fireuser')
const admin = require('firebase-admin')
const serviceWorker = require('path/to/your/json/file');
...
}

Realtime Database Commands

createUser(authID, options)

You'll need this command every time, you want to create a new user in the database. It uses the parameter authID and options . For authID you should use the Firebase Authentication ID of the user. options is an object where you can enter every data the user should have in the database.

// Basic syntax
fireuser.database.createUser(authID, options)

// Example
const authID = req.body.authID;
const rqUsername = req.body.username;
const rqEmail = req.body.email;
const rqFullname = req.body.fullname;

fireuser.database.createUser(authID, {
    username: rqUsername,
    email: rqEmail,
    fullname: rqFullname
});

getUserById(authID)

If you want to retrieve the data of a special user, you can use this function. As parameter, it takes the authID of the user. The function is a promise which returns an object.

fireuser.database.getUserById(authID).then(res => {
    let username = res.username;
    let email = res.email;
    console.log("The username is: " + username);
    console.log("The email address is: " + email);
});

getUserById([authID1, authID2])

coming soon...

changeUserData(authID,options)

Use this command to change data of an existing user. Parameters are the Firebase AuthID and the options object.

fireuser.database.changeUserData(authID, {
    username: newUsername,
    email: newEmail,
    newElement: newElement
});

watchUserChanges(authID,throwbackFunction)

If you want to watch changes of the user data live and interact with it, use this function. You need the Firebase AuthID and a throwback function.

fireuser.database.watchUserChanges(authID, newData => f(newData));

// gets fired every time the user data changes
function tb(newData){
    console.log(newData.username);
}

removeUser(authID)

Removes a user from the database

if(fireuser.database.removeUser(authID)){
    // user removed
}

getUserNumber()

Returns (a promise of) the total amount of users in the databse

fireuser.database.getUserNumber().then(number => console.log(number.toString()));

Firestore Commands

... under construction

Keywords

FAQs

Package last updated on 29 Oct 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc