File tree Expand file tree Collapse file tree 3 files changed +44
-22
lines changed Expand file tree Collapse file tree 3 files changed +44
-22
lines changed Original file line number Diff line number Diff line change 1
- import { useEmulator } from "./emulator" ;
1
+ import { Env , useEmulator } from "./emulator" ;
2
2
import {
3
3
createIdTokenVerifier ,
4
4
FirebaseIdToken ,
5
5
FirebaseTokenVerifier ,
6
6
} from "./token-verifier" ;
7
7
8
- export class Auth {
8
+ export class BaseAuth {
9
9
/** @internal */
10
10
protected readonly idTokenVerifier : FirebaseTokenVerifier ;
11
11
@@ -33,8 +33,8 @@ export class Auth {
33
33
* token's decoded claims if the ID token is valid; otherwise, a rejected
34
34
* promise.
35
35
*/
36
- public verifyIdToken ( idToken : string ) : Promise < FirebaseIdToken > {
37
- const isEmulator = useEmulator ( ) ;
36
+ public verifyIdToken ( idToken : string , env ?: Env ) : Promise < FirebaseIdToken > {
37
+ const isEmulator = useEmulator ( env ) ;
38
38
return this . idTokenVerifier . verifyJWT ( idToken , isEmulator ) ;
39
39
}
40
40
}
Original file line number Diff line number Diff line change 1
- declare global {
2
- // Please set FIREBASE_AUTH_EMULATOR_HOST environment variable in your wrangler.toml.
3
- // see: https://developers.cloudflare.com/workers/platform/environment-variables/#environment-variables-via-wrangler
4
- //
5
- // Example for wrangler.toml
6
- // [vars]
7
- // FIREBASE_AUTH_EMULATOR_HOST = "localhost:8080"
8
- //
9
- // # Override values for `--env production` usage
10
- // [env.production.vars]
11
- // FIREBASE_AUTH_EMULATOR_HOST = ""
12
- const FIREBASE_AUTH_EMULATOR_HOST : string | undefined ;
1
+ export interface Env {
2
+ FIREBASE_AUTH_EMULATOR_HOST : string | undefined
13
3
}
14
4
15
- function emulatorHost ( ) : string | undefined {
16
- return FIREBASE_AUTH_EMULATOR_HOST ;
5
+ export function emulatorHost ( env ?: Env ) : string | undefined {
6
+ return env ?. FIREBASE_AUTH_EMULATOR_HOST ;
17
7
}
18
8
19
9
/**
20
10
* When true the SDK should communicate with the Auth Emulator for all API
21
11
* calls and also produce unsigned tokens.
22
12
*/
23
- export const useEmulator = ( ) : boolean => {
24
- return ! ! emulatorHost ( ) ;
13
+ export const useEmulator = ( env ?: Env ) : boolean => {
14
+ return ! ! emulatorHost ( env ) ;
25
15
} ;
Original file line number Diff line number Diff line change
1
+ import { BaseAuth } from "./auth"
2
+
3
+
1
4
export {
2
- Auth
3
- } from "./auth"
5
+ emulatorHost ,
6
+ useEmulator
7
+ } from "./emulator"
8
+ export type { Env } from './emulator'
9
+
10
+ export class Auth extends BaseAuth {
11
+ private static instance ?: Auth ;
12
+
13
+ private constructor (
14
+ projectId : string ,
15
+ cacheKey : string ,
16
+ cfPublicKeyCacheNamespace : KVNamespace
17
+ ) {
18
+ super ( projectId , cacheKey , cfPublicKeyCacheNamespace )
19
+ }
20
+
21
+ static getOrInitialize (
22
+ projectId : string ,
23
+ cacheKey : string ,
24
+ cfPublicKeyCacheNamespace : KVNamespace
25
+ ) : Auth {
26
+ if ( ! Auth . instance ) {
27
+ Auth . instance = new Auth (
28
+ projectId ,
29
+ cacheKey ,
30
+ cfPublicKeyCacheNamespace ,
31
+ )
32
+ }
33
+ return Auth . instance
34
+ }
35
+ }
You can’t perform that action at this time.
0 commit comments