1
- import { Auth } from '@firebase/auth-exp' ;
2
- import { getApps } from '@firebase/app-exp' ;
1
+ /**
2
+ * @license
3
+ * Copyright 2020 Google LLC
4
+ *
5
+ * Licensed under the Apache License, Version 2.0 (the "License");
6
+ * you may not use this file except in compliance with the License.
7
+ * You may obtain a copy of the License at
8
+ *
9
+ * http://www.apache.org/licenses/LICENSE-2.0
10
+ *
11
+ * Unless required by applicable law or agreed to in writing, software
12
+ * distributed under the License is distributed on an "AS IS" BASIS,
13
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ * See the License for the specific language governing permissions and
15
+ * limitations under the License.
16
+ */
17
+
18
+ import { Auth } from '@firebase/auth-exp' ;
19
+ import { getApps } from '@firebase/app-exp' ;
3
20
4
21
interface VerificationSession {
5
22
code : string ;
@@ -11,19 +28,21 @@ interface VerificationCodesResponse {
11
28
verificationCodes : VerificationSession [ ] ;
12
29
}
13
30
14
- export async function getPhoneVerificationCodes ( auth : Auth ) : Promise < Record < string , VerificationSession > > {
31
+ export async function getPhoneVerificationCodes (
32
+ auth : Auth
33
+ ) : Promise < Record < string , VerificationSession > > {
15
34
assertEmulator ( auth ) ;
16
35
const url = getEmulatorUrl ( auth , 'verificationCodes' ) ;
17
36
const response : VerificationCodesResponse = await ( await fetch ( url ) ) . json ( ) ;
18
-
37
+
19
38
return response . verificationCodes . reduce ( ( accum , session ) => {
20
39
accum [ session . sessionInfo ] = session ;
21
40
return accum ;
22
41
} , { } as Record < string , VerificationSession > ) ;
23
42
}
24
43
25
44
function getEmulatorUrl ( auth : Auth , endpoint : string ) : string {
26
- const { host, port, protocol} = auth . emulatorConfig ! ;
45
+ const { host, port, protocol } = auth . emulatorConfig ! ;
27
46
const projectId = getProjectId ( auth ) ;
28
47
return `${ protocol } ://${ host } :${ port } /emulator/v1/projects/${ projectId } /${ endpoint } ` ;
29
48
}
@@ -34,6 +53,6 @@ function getProjectId(auth: Auth): string {
34
53
35
54
function assertEmulator ( auth : Auth ) : void {
36
55
if ( ! auth . emulatorConfig ) {
37
- throw new Error ( ' Can\ 't fetch OOB codes against prod API' ) ;
56
+ throw new Error ( " Can't fetch OOB codes against prod API" ) ;
38
57
}
39
- }
58
+ }
0 commit comments