From 4e2084b9a8e5fa99e47170566c07a3d01ef30bb2 Mon Sep 17 00:00:00 2001 From: Kei Kamikawa Date: Fri, 29 Jul 2022 23:19:27 +0900 Subject: [PATCH] fixed README for service worker mode --- README.md | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/README.md b/README.md index 03012f56..38453c19 100644 --- a/README.md +++ b/README.md @@ -6,6 +6,8 @@ Currently only Cloudflare Workers are supported officially. However, it may work ## Synopsis +### Module Worker Syntax (recommend) + ```ts import { Hono } from "hono"; import { VerifyFirebaseAuthConfig, VerifyFirebaseAuthEnv, verifyFirebaseAuth, getFirebaseToken } from "@honojs/firebase-auth"; @@ -28,6 +30,37 @@ app.get("/hello", (c) => { export default app ``` +### Service Worker Syntax + +```ts +import { Hono } from "hono"; +import { VerifyFirebaseAuthConfig, verifyFirebaseAuth, getFirebaseToken } from "@honojs/firebase-auth"; + +const config: VerifyFirebaseAuthConfig = { + // specify your firebase project ID. + projectId: "your-project-id", + // this is optional. but required in this mode. + keyStore: WorkersKVStoreSingle.getOrInitialize( + PUBLIC_JWK_CACHE_KEY, + PUBLIC_JWK_CACHE_KV + ), + // this is also optional. But in this mode, you can only specify here. + firebaseEmulatorHost: FIREBASE_AUTH_EMULATOR_HOST, +} + +const app = new Hono() + +// set middleware +app.use("*", verifyFirebaseAuth(config)); +app.get("/hello", (c) => { + const idToken = getFirebaseToken(c) // get id-token object. + return c.json(idToken) +}); + +app.fire() +``` + + ## Config (`VerifyFirebaseAuthConfig`) ### `projectId: string` (**required**) @@ -54,6 +87,12 @@ If you don't specify the field, this library uses [WorkersKVStoreSingle](https:/ Throws an exception if JWT validation fails. By default, this is output to the error log, but if you don't expect it, use this. +### `firebaseEmulatorHost?: string` (optional) + +You can specify a host for the Firebase Auth emulator. This config is mainly used when **Service Worker Syntax** is used. + +If not specified, check the [`FIREBASE_AUTH_EMULATOR_HOST` environment variable obtained from the request](https://github.com/Code-Hex/firebase-auth-cloudflare-workers#emulatorenv). + ## Author codehex