Skip to content

Commit

Permalink
‼️ change first argument obj to appInstance
Browse files Browse the repository at this point in the history
  • Loading branch information
59naga committed Aug 16, 2018
1 parent c12c5f4 commit 045a247
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 18 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -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);

Expand Down
11 changes: 2 additions & 9 deletions index.mjs
Original file line number Diff line number Diff line change
@@ -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 = {};
Expand Down Expand Up @@ -41,9 +37,6 @@ export default ({ credential }, options = {}) => {
middleware.deleteCache = key => {
delete cache[key];
};
middleware.firebaseAdminClose = () => {
app.delete();
};

middleware.extra = {
verifyCustomTokenUrl:
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down
10 changes: 7 additions & 3 deletions test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});

Expand Down

0 comments on commit 045a247

Please sign in to comment.