Skip to content

Commit e2b4f73

Browse files
fix(firebase-auth): expose Context type param for Env
1 parent 08eda5a commit e2b4f73

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

.github/workflows/ci-firebase-auth.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,18 @@ on:
1212
jobs:
1313
ci:
1414
runs-on: ubuntu-latest
15+
strategy:
16+
matrix:
17+
hono-version: [hono@^3.0.0]
18+
# hono-version: ['hono@^3.0.0', 'hono@^4.0.0']
1519
steps:
1620
- uses: actions/checkout@v4
1721
- uses: actions/setup-node@v4
1822
with:
1923
node-version: 20.x
24+
- run: yarn add ${{ matrix.hono-version }} --mode=update-lockfile
2025
- run: yarn workspaces focus hono-middleware @hono/firebase-auth
21-
- run: yarn workspace @hono/firebase-auth build
26+
- run: yarn workspaces foreach --topological --recursive --from @hono/firebase-auth run build
2227
- run: yarn workspace @hono/firebase-auth publint
2328
- run: yarn test --coverage --project @hono/firebase-auth
2429
- uses: codecov/codecov-action@v5

packages/firebase-auth/src/index.ts

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { KeyStorer, FirebaseIdToken } from 'firebase-auth-cloudflare-workers'
22
import { Auth, WorkersKVStoreSingle } from 'firebase-auth-cloudflare-workers'
3-
import type { Context, MiddlewareHandler } from 'hono'
3+
import type { Context, Env, MiddlewareHandler } from 'hono'
44
import { getCookie } from 'hono/cookie'
55
import { HTTPException } from 'hono/http-exception'
66

@@ -10,17 +10,19 @@ export type VerifyFirebaseAuthEnv = {
1010
FIREBASE_AUTH_EMULATOR_HOST: string | undefined
1111
}
1212

13-
export interface VerifyFirebaseAuthConfig {
13+
export interface VerifyFirebaseAuthConfig<E extends Env> {
1414
projectId: string
1515
authorizationHeaderKey?: string
1616
keyStore?: KeyStorer
17-
keyStoreInitializer?: (c: Context) => KeyStorer
17+
keyStoreInitializer?: (c: Context<E>) => KeyStorer
1818
disableErrorLog?: boolean
1919
firebaseEmulatorHost?: string
2020
}
2121

2222
const defaultKVStoreJWKCacheKey = 'verify-firebase-auth-cached-public-key'
23-
const defaultKeyStoreInitializer = (c: Context<{ Bindings: VerifyFirebaseAuthEnv }>): KeyStorer => {
23+
const defaultKeyStoreInitializer = <E extends { Bindings: VerifyFirebaseAuthEnv }>(
24+
c: Context<E>
25+
): KeyStorer => {
2426
if (c.env.PUBLIC_JWK_CACHE_KV === undefined) {
2527
const status = 501
2628
throw new HTTPException(status, {
@@ -33,15 +35,17 @@ const defaultKeyStoreInitializer = (c: Context<{ Bindings: VerifyFirebaseAuthEnv
3335
)
3436
}
3537

36-
export const verifyFirebaseAuth = (userConfig: VerifyFirebaseAuthConfig): MiddlewareHandler => {
38+
export const verifyFirebaseAuth = <E extends { Bindings: VerifyFirebaseAuthEnv }>(
39+
userConfig: VerifyFirebaseAuthConfig<E>
40+
): MiddlewareHandler<E> => {
3741
const config = {
3842
projectId: userConfig.projectId,
3943
authorizationHeaderKey: userConfig.authorizationHeaderKey ?? 'Authorization',
4044
keyStore: userConfig.keyStore,
4145
keyStoreInitializer: userConfig.keyStoreInitializer ?? defaultKeyStoreInitializer,
4246
disableErrorLog: userConfig.disableErrorLog,
4347
firebaseEmulatorHost: userConfig.firebaseEmulatorHost,
44-
} satisfies VerifyFirebaseAuthConfig
48+
} satisfies VerifyFirebaseAuthConfig<E>
4549

4650
// TODO(codehex): will be supported
4751
const checkRevoked = false
@@ -102,7 +106,7 @@ export interface VerifySessionCookieFirebaseAuthConfig {
102106
projectId: string
103107
cookieName?: string
104108
keyStore?: KeyStorer
105-
keyStoreInitializer?: (c: Context) => KeyStorer
109+
keyStoreInitializer?: (c: Context<{ Bindings: VerifyFirebaseAuthEnv }>) => KeyStorer
106110
firebaseEmulatorHost?: string
107111
redirects: {
108112
signIn: string
@@ -111,7 +115,7 @@ export interface VerifySessionCookieFirebaseAuthConfig {
111115

112116
export const verifySessionCookieFirebaseAuth = (
113117
userConfig: VerifySessionCookieFirebaseAuthConfig
114-
): MiddlewareHandler => {
118+
): MiddlewareHandler<{ Bindings: VerifyFirebaseAuthEnv }> => {
115119
const config = {
116120
projectId: userConfig.projectId,
117121
cookieName: userConfig.cookieName ?? 'session',

0 commit comments

Comments
 (0)