@@ -19,27 +19,13 @@ import { expect, use } from 'chai';
19
19
import * as chaiAsPromised from 'chai-as-promised' ;
20
20
21
21
import {
22
- linkWithPhoneNumber ,
23
- PhoneAuthProvider ,
24
- reauthenticateWithPhoneNumber ,
25
- RecaptchaVerifier ,
26
- signInAnonymously ,
27
- signInWithPhoneNumber ,
28
- unlink ,
29
- updatePhoneNumber
22
+ linkWithPhoneNumber , PhoneAuthProvider , reauthenticateWithPhoneNumber , RecaptchaVerifier ,
23
+ signInAnonymously , signInWithPhoneNumber , unlink , updatePhoneNumber
30
24
} from '@firebase/auth-exp/index.browser' ;
31
- import {
32
- Auth ,
33
- OperationType ,
34
- ProviderId ,
35
- UserCredential
36
- } from '@firebase/auth-types-exp' ;
25
+ import { Auth , OperationType , ProviderId , UserCredential } from '@firebase/auth-types-exp' ;
37
26
import { FirebaseError } from '@firebase/util' ;
38
27
39
- import {
40
- cleanUpTestInstance ,
41
- getTestInstance
42
- } from '../../helpers/integration/helpers' ;
28
+ import { cleanUpTestInstance , getTestInstance } from '../../helpers/integration/helpers' ;
43
29
44
30
use ( chaiAsPromised ) ;
45
31
@@ -51,12 +37,12 @@ use(chaiAsPromised);
51
37
// • +1 (555) 555-2000, SMS code 654321
52
38
53
39
const PHONE_A = {
54
- number : '+15555551000' ,
40
+ phoneNumber : '+15555551000' ,
55
41
code : '123456'
56
42
} ;
57
43
58
44
const PHONE_B = {
59
- number : '+15555552000' ,
45
+ phoneNumber : '+15555552000' ,
60
46
code : '654321'
61
47
} ;
62
48
@@ -78,7 +64,7 @@ describe('Integration test: phone auth', () => {
78
64
} ) ;
79
65
80
66
it ( 'allows user to sign up' , async ( ) => {
81
- const cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
67
+ const cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
82
68
const userCred = await cr . confirm ( PHONE_A . code ) ;
83
69
84
70
expect ( auth . currentUser ) . to . eq ( userCred . user ) ;
@@ -87,18 +73,18 @@ describe('Integration test: phone auth', () => {
87
73
const user = userCred . user ;
88
74
expect ( user . isAnonymous ) . to . be . false ;
89
75
expect ( user . uid ) . to . be . a ( 'string' ) ;
90
- expect ( user . phoneNumber ) . to . eq ( PHONE_A . number ) ;
76
+ expect ( user . phoneNumber ) . to . eq ( PHONE_A . phoneNumber ) ;
91
77
} ) ;
92
78
93
79
it ( 'anonymous users can link (and unlink) phone number' , async ( ) => {
94
80
const { user } = await signInAnonymously ( auth ) ;
95
81
const { uid : anonId } = user ;
96
82
97
- const cr = await linkWithPhoneNumber ( user , PHONE_A . number , verifier ) ;
83
+ const cr = await linkWithPhoneNumber ( user , PHONE_A . phoneNumber , verifier ) ;
98
84
const linkResult = await cr . confirm ( PHONE_A . code ) ;
99
85
expect ( linkResult . operationType ) . to . eq ( OperationType . LINK ) ;
100
86
expect ( linkResult . user . uid ) . to . eq ( user . uid ) ;
101
- expect ( linkResult . user . phoneNumber ) . to . eq ( PHONE_A . number ) ;
87
+ expect ( linkResult . user . phoneNumber ) . to . eq ( PHONE_A . phoneNumber ) ;
102
88
103
89
await unlink ( user , ProviderId . PHONE ) ;
104
90
expect ( auth . currentUser ! . uid ) . to . eq ( anonId ) ;
@@ -115,65 +101,65 @@ describe('Integration test: phone auth', () => {
115
101
}
116
102
117
103
beforeEach ( async ( ) => {
118
- const cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
104
+ const cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
119
105
signUpCred = await cr . confirm ( PHONE_A . code ) ;
120
106
resetVerifier ( ) ;
121
107
await auth . signOut ( ) ;
122
108
} ) ;
123
109
124
110
it ( 'allows the user to sign in again' , async ( ) => {
125
- const cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
111
+ const cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
126
112
const signInCred = await cr . confirm ( PHONE_A . code ) ;
127
113
128
114
expect ( signInCred . user . uid ) . to . eq ( signUpCred . user . uid ) ;
129
115
} ) ;
130
116
131
117
it ( 'allows the user to update their phone number' , async ( ) => {
132
- let cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
118
+ let cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
133
119
const { user } = await cr . confirm ( PHONE_A . code ) ;
134
120
135
121
resetVerifier ( ) ;
136
122
137
123
const provider = new PhoneAuthProvider ( auth ) ;
138
124
const verificationId = await provider . verifyPhoneNumber (
139
- PHONE_B . number ,
125
+ PHONE_B . phoneNumber ,
140
126
verifier
141
127
) ;
142
128
143
129
await updatePhoneNumber (
144
130
user ,
145
131
PhoneAuthProvider . credential ( verificationId , PHONE_B . code )
146
132
) ;
147
- expect ( user . phoneNumber ) . to . eq ( PHONE_B . number ) ;
133
+ expect ( user . phoneNumber ) . to . eq ( PHONE_B . phoneNumber ) ;
148
134
149
135
await auth . signOut ( ) ;
150
136
resetVerifier ( ) ;
151
137
152
- cr = await signInWithPhoneNumber ( auth , PHONE_B . number , verifier ) ;
138
+ cr = await signInWithPhoneNumber ( auth , PHONE_B . phoneNumber , verifier ) ;
153
139
const { user : secondSignIn } = await cr . confirm ( PHONE_B . code ) ;
154
140
expect ( secondSignIn . uid ) . to . eq ( user . uid ) ;
155
141
} ) ;
156
142
157
143
it ( 'allows the user to reauthenticate with phone number' , async ( ) => {
158
- let cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
144
+ let cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
159
145
const { user } = await cr . confirm ( PHONE_A . code ) ;
160
146
const oldToken = user . refreshToken ;
161
147
162
148
resetVerifier ( ) ;
163
149
164
- cr = await reauthenticateWithPhoneNumber ( user , PHONE_A . number , verifier ) ;
150
+ cr = await reauthenticateWithPhoneNumber ( user , PHONE_A . phoneNumber , verifier ) ;
165
151
await cr . confirm ( PHONE_A . code ) ;
166
152
167
153
expect ( user . refreshToken ) . not . to . eq ( oldToken ) ;
168
154
} ) ;
169
155
170
156
it ( 'prevents reauthentication with wrong phone number' , async ( ) => {
171
- let cr = await signInWithPhoneNumber ( auth , PHONE_A . number , verifier ) ;
157
+ let cr = await signInWithPhoneNumber ( auth , PHONE_A . phoneNumber , verifier ) ;
172
158
const { user } = await cr . confirm ( PHONE_A . code ) ;
173
159
174
160
resetVerifier ( ) ;
175
161
176
- cr = await reauthenticateWithPhoneNumber ( user , PHONE_B . number , verifier ) ;
162
+ cr = await reauthenticateWithPhoneNumber ( user , PHONE_B . phoneNumber , verifier ) ;
177
163
await expect ( cr . confirm ( PHONE_B . code ) ) . to . be . rejectedWith (
178
164
FirebaseError ,
179
165
'auth/user-mismatch'
@@ -182,7 +168,7 @@ describe('Integration test: phone auth', () => {
182
168
// We need to manually delete PHONE_B number since a failed
183
169
// reauthenticateWithPhoneNumber does not trigger a state change
184
170
resetVerifier ( ) ;
185
- cr = await signInWithPhoneNumber ( auth , PHONE_B . number , verifier ) ;
171
+ cr = await signInWithPhoneNumber ( auth , PHONE_B . phoneNumber , verifier ) ;
186
172
const { user : otherUser } = await cr . confirm ( PHONE_B . code ) ;
187
173
await otherUser . delete ( ) ;
188
174
} ) ;
0 commit comments