diff --git a/README.md b/README.md index b007e59..a7edc17 100644 --- a/README.md +++ b/README.md @@ -21,9 +21,7 @@ yarn add socket.io-middleware-firebase-admin API --- -## createIoMiddlewareFirebaseAdmin({ credential }, (options = {})): middleware - -[initialize "Firebase Admin SDK" using `credential`](https://firebase.google.com/docs/admin/setup) +## createIoMiddlewareFirebaseAdmin(app, (options = {})): middleware ```js import { createServer } from "http"; @@ -35,7 +33,10 @@ import credential from "./.credential"; const server = createServer(); const io = createIoServer(server); -const ioMiddleware = createIoMiddlewareFirebaseAdmin({ credential }); +const app = firebaseAdmin.initializeApp({ + credential: firebaseAdmin.credential.cert(credential) +}); +const ioMiddleware = createIoMiddlewareFirebaseAdmin(app); io.use(ioMiddleware); diff --git a/index.mjs b/index.mjs index 72858fa..918d08a 100644 --- a/index.mjs +++ b/index.mjs @@ -1,11 +1,7 @@ -import firebaseAdmin from "firebase-admin"; import cookie from "cookie"; -export default ({ credential }, options = {}) => { - const app = firebaseAdmin.initializeApp({ - credential: firebaseAdmin.credential.cert(credential) - }); - const auth = firebaseAdmin.auth(); +export default (app, options = {}) => { + const auth = app.auth(); const opts = Object.assign({ deny: true, cache: true }, options); const cache = {}; @@ -41,9 +37,6 @@ export default ({ credential }, options = {}) => { middleware.deleteCache = key => { delete cache[key]; }; - middleware.firebaseAdminClose = () => { - app.delete(); - }; middleware.extra = { verifyCustomTokenUrl: diff --git a/package.json b/package.json index e893b04..16c4172 100644 --- a/package.json +++ b/package.json @@ -10,8 +10,7 @@ "postversion": "git push --follow-tags && conventional-github-releaser -p atom" }, "dependencies": { - "cookie": "^0.3.1", - "firebase-admin": "^6.0.0" + "cookie": "^0.3.1" }, "devDependencies": { "@babel/cli": "^7.0.0-rc.1", @@ -22,6 +21,7 @@ "babel-plugin-add-module-exports": "^0.3.3", "bluebird": "^3.5.1", "eastern": "^0.1.0", + "firebase-admin": "^6.0.0", "prettier": "^1.14.2", "request": "^2.88.0", "server-destroy": "^1.0.1", diff --git a/test.mjs b/test.mjs index ab6d3f4..c7f6f29 100644 --- a/test.mjs +++ b/test.mjs @@ -8,17 +8,21 @@ import { createIoClientAsync, createSession } from "./test-helpers"; +import firebaseAdmin from "firebase-admin"; import createFirebaseAdminMiddlware from "./"; import credential from "./.credential"; -let middleware, server, port; +let app, middleware, server, port; spec.before(async () => { - middleware = createFirebaseAdminMiddlware({ credential }); + app = firebaseAdmin.initializeApp({ + credential: firebaseAdmin.credential.cert(credential) + }); + middleware = createFirebaseAdminMiddlware(app); server = await createIoServerAsync(middleware); port = server.address().port; }); spec.after(async () => { - middleware.firebaseAdminClose(); + app.delete(); server.destroy(); });