fixed README for service worker mode

pull/34/head
Kei Kamikawa 2022-07-29 23:19:27 +09:00
parent 923c6d0952
commit 4e2084b9a8
No known key found for this signature in database
GPG Key ID: 1A9F69C08C8C7A8E
1 changed files with 39 additions and 0 deletions

View File

@ -6,6 +6,8 @@ Currently only Cloudflare Workers are supported officially. However, it may work
## Synopsis ## Synopsis
### Module Worker Syntax (recommend)
```ts ```ts
import { Hono } from "hono"; import { Hono } from "hono";
import { VerifyFirebaseAuthConfig, VerifyFirebaseAuthEnv, verifyFirebaseAuth, getFirebaseToken } from "@honojs/firebase-auth"; import { VerifyFirebaseAuthConfig, VerifyFirebaseAuthEnv, verifyFirebaseAuth, getFirebaseToken } from "@honojs/firebase-auth";
@ -28,6 +30,37 @@ app.get("/hello", (c) => {
export default app 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`) ## Config (`VerifyFirebaseAuthConfig`)
### `projectId: string` (**required**) ### `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. 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 ## Author
codehex <https://github.com/Code-Hex> codehex <https://github.com/Code-Hex>