Skip to content

fingunt/adonis5-firebase-admin

 
 

Repository files navigation

Table of contents

Adonis5-Firebase-Admin

Adonisjs 5, Firebase admin, Firebase for Adonis5

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

About

Firebase admin provider for AdonisJS 5

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 93.8%
  • JavaScript 6.2%