@microbackend/plugin-firebase
v1.0.1
Published
Micro-backend Firebase plugin
Downloads
10
Readme
@microbackend/plugin-firebase
Microbackend plugin to add support for firebase.
Installation
npx microbackend plugin add @microbackend/plugin-firebase
Usage
import createPluginConfig from "@microbackend/plugin-core/build/webpack.build";
await createPluginConfig({
pluginOptions: {
"@microbackend/plugin-firebase": {
serviceAccountEnvVariable: "CUSTOM_GOOGLE_SERVICE_ACCOUNT",
serviceAccountPath: path.resolve(
"credential",
"google_service_account.json"
),
},
},
});
If not provided, serviceAccountEnvVariable
defaults to
GOOGLE_SERVICE_ACCOUNT_CREDENTIALS
.
The above configuration does the following steps:
- Read the service account file specified by
serviceAccountPath
. - Store the service account credentials in the environment variable specified
by
serviceAccountEnvVariable
, which can then be accessed during runtime like this:process.env["CUSTOM_GOOGLE_SERVICE_ACCOUNT"]
.
The plugin creates an extension on app
to expose a firebaseAdmin
property
using the service account credentials.
app.use((req, res, next) => {
const firebaseAuth = req.app.firebaseAdmin.auth();
/** Perform auth */
next();
});
For more information on how to use the firebase Node.js SDK, please read its documentation.