18
18
// eslint-disable-next-line import/no-extraneous-dependencies
19
19
import { Auth } from '@firebase/auth-exp' ;
20
20
import { getApps } from '@firebase/app-exp' ;
21
+ import { FetchProvider } from '../../../src/core/util/fetch_provider' ;
22
+ import * as fetchImpl from 'node-fetch' ;
21
23
22
- interface VerificationSession {
24
+ if ( typeof document !== 'undefined' ) {
25
+ FetchProvider . initialize ( fetch ) ;
26
+ } else {
27
+ FetchProvider . initialize (
28
+ ( fetchImpl . default as unknown ) as typeof fetch ,
29
+ ( fetchImpl . Headers as unknown ) as typeof Headers ,
30
+ ( fetchImpl . Response as unknown ) as typeof Response
31
+ ) ;
32
+ }
33
+
34
+ export interface VerificationSession {
23
35
code : string ;
24
36
phoneNumber : string ;
25
37
sessionInfo : string ;
@@ -29,19 +41,41 @@ interface VerificationCodesResponse {
29
41
verificationCodes : VerificationSession [ ] ;
30
42
}
31
43
44
+ export interface OobCodeSession {
45
+ email : string ;
46
+ requestType : string ;
47
+ oobCode : string ;
48
+ oobLink : string ;
49
+ }
50
+
51
+ interface OobCodesResponse {
52
+ oobCodes : OobCodeSession [ ] ;
53
+ }
54
+
32
55
export async function getPhoneVerificationCodes (
33
56
auth : Auth
34
57
) : Promise < Record < string , VerificationSession > > {
35
58
assertEmulator ( auth ) ;
36
59
const url = getEmulatorUrl ( auth , 'verificationCodes' ) ;
37
- const response : VerificationCodesResponse = await ( await fetch ( url ) ) . json ( ) ;
60
+ const response : VerificationCodesResponse = await (
61
+ await FetchProvider . fetch ( ) ( url )
62
+ ) . json ( ) ;
38
63
39
64
return response . verificationCodes . reduce ( ( accum , session ) => {
40
65
accum [ session . sessionInfo ] = session ;
41
66
return accum ;
42
67
} , { } as Record < string , VerificationSession > ) ;
43
68
}
44
69
70
+ export async function getOobCodes ( auth : Auth ) : Promise < OobCodeSession [ ] > {
71
+ assertEmulator ( auth ) ;
72
+ const url = getEmulatorUrl ( auth , 'oobCodes' ) ;
73
+ const response : OobCodesResponse = await (
74
+ await FetchProvider . fetch ( ) ( url )
75
+ ) . json ( ) ;
76
+ return response . oobCodes ;
77
+ }
78
+
45
79
function getEmulatorUrl ( auth : Auth , endpoint : string ) : string {
46
80
const { host, port, protocol } = auth . emulatorConfig ! ;
47
81
const projectId = getProjectId ( auth ) ;
0 commit comments