firebase-verifier
v1.0.19
Published
Expressjs Middleware for firebase authentication and app check when you don't want to install firebase admin sdk
Downloads
11
Maintainers
Readme
firebase-verifier
middleware for expressjs
When you don't want to install firebase-admin-sdk
just to verify id token
and/or app check token
.
Install
npm install firebase-verifier
Configs
Obtains project_id
and project_no
from Google Cloud Console
Usage
import express from "express";
import {
authVerifier,
appCheckVerifier,
firebaseVerifier,
} from "firebase-verifier";
const project_id = "<project_id>";
const project_no = "<project_no>";
const app = express();
// Verify Id token
app.use(authVerifier(project_id));
app.get("/", (req, res) => {
console.log(res.locals.user);
/* Output
{
"sub": "kxljssoieeJKLe",
"email": "[email protected]",
...
}
*/
});
...
// Verify App Check token
app.use(appCheckVerifier(project_no));
app.get("/", (req, res) => {
console.log(res.locals.device);
/* Output
{
...
}
*/
});
...
// Verify both Id token and App Check token
app.use(firebaseVerifier({ project_id, project_no }));
app.get("/", (req, res) => {
console.log(res.locals.user);
console.log(res.locals.device);
});
app.listen(3000);
Check verification
If any of the verifiers failed, res.locals.user
, res.locals.device
are null and res.locals.error
contains the error.