Skip to content
This repository has been archived by the owner on Jun 4, 2022. It is now read-only.

rollivier/adonis5-firebase-admin

Repository files navigation

⛔️ DEPRECATED

Actually, we don't use this repository anymore and it suffers from a lack of dependency updates that can create security issues. You can freely use the code to create your own firebase integration

Table of contents

Adonis5-Firebase-Admin

Adonisjs 5, Firebase admin, Firebase for Adonis5

nomaintenance-image typescript-image license-image npm-image

Firebase admin providers for AdonisJS 5

Installation

npm i --save adonis5-firebase-admin

Compile your code:

node ace serve --watch

Connect all dependences:

node ace invoke adonis5-firebase-admin
  • For other configuration, please update the config/firebase.ts.

Usage

After adding firebase-admin provider to your app, you can import firebaseAdmin to access all the functions of the firebase admin

import firebaseAdmin from '@ioc:Adonis/Addons/FirebaseAdmin'
  • For example, you can create a middleware to check if the user is authenticated.
node ace make:middleware Authenticate
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import firebaseAdmin from '@ioc:Adonis/Addons/FirebaseAdmin'

export default class Authenticate {
  public async handle ({ request, response }: HttpContextContract, next: () => Promise<void>) {
    const idToken = request.header('Authorization') as string
    firebaseAdmin.auth().verifyIdToken(idToken)
      .then(async function (decodedToken) {
        const uid = decodedToken.uid
        ...
        await next()
      }).catch(function (error) {
        response.status(401).send(error)
      })
  }
}

For additional details of Firebase Admin API, please check the Firebase SDK documentation by this link Firebase docs