Skip to content

Firebase

Glossary

admin

All functions from this module require admin dependency. What is this admin anyway?

The word admin actually refers to firebase-admin NPM package, aka. Firebase Admin Node SDK. The admin object has to be already configurated.

What is this module for?

This module is for helping developers who want to use Firebase with SteemConnect.

It contains functions for minting custom auth tokens, saving access token in the Firestore, getting access token from Firestore, and creating or updating user auth account.

API reference

Functions

createFirebaseAccount

export declare function createFirebaseAccount(
  admin: any,
  {
    uid,
    username,
    photoURL,
    email,
    emailVerified,
    phoneNumber,
    disabled
  }: FirebaseAccount
): Promise<any>;
Definition

Creates or updates Firebase auth user account.

Parameters
Returns
  • (Promise): the Promise object
Example Usage
import {
  createFirebaseAccount,
  FirebaseAccount
} from 'steemconnect-firebase-functions';
import * as admin from 'firebase-admin';

const serviceAccount = require('../serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const firebaseAccountConfig: FirebaseAccount = {
  uid: 'steemconnect:jakipatryk',
  username: 'jakipatryk',
  photoURL: 'https://some-uri.com/avatar.jpg'
};

createFirebaseAccount(admin, firebaseAccountConfig).then(() => {
  console.log(5 * 20 + 11);
});
Implementation

The implementation is available on Github.


mintFirebaseToken

export declare function mintFirebaseToken(
  admin: any,
  uid: string
): Promise<string>;
Definition

Creates and returns Firebase custom auth token.

Parameters
  • admin
  • uid (string): the uid of the user you want to mint custom Firebase auth token for
Returns

(Promise): the Promise object which resolves with Firebase custom auth token

Example Usage
import { mintFirebaseToken } from 'steemconnect-firebase-functions';
import * as admin from 'firebase-admin';

const serviceAccount = require('../serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const uid = 'steemconnect:jakipatryk';

mintFirebaseToken(admin, uid).then(token => {
  console.log(token);
});
Implementation

The implementation is available on Github.


saveAccessToken

export declare function saveAccessToken(
  admin: any,
  uid: string,
  accessToken: AccessTokenResponse
): Promise<any>;
Definition

Saves access token and its details in the Firestore.

Parameters
Returns
  • (Promise): the Promise object
Example Usage
import { saveAccessToken } from 'steemconnect-firebase-functions';
import * as admin from 'firebase-admin';

const serviceAccount = require('../serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const uid = 'steemconnect:jakipatryk';
const accessToken = {
  access_token: '423423432.fsdfewf43',
  expires_in: 4200000,
  username: 'jakipatryk',
  refresh_token: '4u5jnj4f3.543jim43i'
};

saveAccessToken(admin, uid, accessToken).then(() => {
  console.log(2 + 2 * 4);
});
Implementation

The implementation is available on Github.


getAccessTokenFromFirestore

export declare function getAccessTokenFromFirestore(
  admin: any,
  uid: string
): Promise<AccessTokenResponse>;
Definition

Gets and returns the access token + details object from the Firestore.

Parameters
  • admin
  • uid (string): the uid of the user you want to get access token for
Returns
  • (Promise<AccessTokenResponse>): the Promise object which resolves with the AccessTokenResponse object
Example Usage
import { getAccessTokenFromFirestore } from 'steemconnect-firebase-functions';
import * as admin from 'firebase-admin';

const serviceAccount = require('../serviceAccountKey.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

const uid = 'steemconnect:jakipatryk';

getAccessTokenFromFirestore(admin, uid).then(tokens => console.log(tokens));
Implementation

The implementation is available on Github.


Interfaces

FirebaseAccount

Definition

Defines Firebase account object.

Implementation
export interface FirebaseAccount {
  uid: string;
  username: string;
  photoURL?: string;
  email?: string;
  emailVerified?: boolean;
  phoneNumber?: string;
  disabled?: boolean;
}