项目作者: rollivier

项目描述 :
Firebase admin provider for AdonisJS 5
高级语言: TypeScript
项目地址: git://github.com/rollivier/adonis5-firebase-admin.git
创建时间: 2020-11-06T18:18:41Z
项目社区:https://github.com/rollivier/adonis5-firebase-admin

开源协议:MIT License

下载


⛔️ 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

  1. npm i --save adonis5-firebase-admin

Compile your code:

  1. node ace serve --watch

Connect all dependences:

  1. 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

  1. import firebaseAdmin from '@ioc:Adonis/Addons/FirebaseAdmin'
  • For example, you can create a middleware to check if the user is authenticated.
  1. node ace make:middleware Authenticate
  1. import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
  2. import firebaseAdmin from '@ioc:Adonis/Addons/FirebaseAdmin'
  3. export default class Authenticate {
  4. public async handle ({ request, response }: HttpContextContract, next: () => Promise<void>) {
  5. const idToken = request.header('Authorization') as string
  6. firebaseAdmin.auth().verifyIdToken(idToken)
  7. .then(async function (decodedToken) {
  8. const uid = decodedToken.uid
  9. ...
  10. await next()
  11. }).catch(function (error) {
  12. response.status(401).send(error)
  13. })
  14. }
  15. }

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