1
- import { Auth , createUserWithEmailAndPassword , EmailAuthProvider , linkWithCredential , OperationType , signInAnonymously , signInWithCustomToken , signInWithEmailAndPassword , updateEmail , updatePassword } from '@firebase/auth-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 {
19
+ Auth ,
20
+ createUserWithEmailAndPassword ,
21
+ EmailAuthProvider ,
22
+ linkWithCredential ,
23
+ OperationType ,
24
+ signInAnonymously ,
25
+ signInWithCustomToken ,
26
+ signInWithEmailAndPassword ,
27
+ updateEmail ,
28
+ updatePassword
29
+ } from '@firebase/auth-exp' ;
2
30
import { FirebaseError } from '@firebase/util' ;
3
31
import { expect , use } from 'chai' ;
4
32
import * as chaiAsPromised from 'chai-as-promised' ;
5
- import { cleanUpTestInstance , getTestInstance , randomEmail } from '../../helpers/integration/helpers' ;
33
+ import {
34
+ cleanUpTestInstance ,
35
+ getTestInstance ,
36
+ randomEmail
37
+ } from '../../helpers/integration/helpers' ;
6
38
7
39
use ( chaiAsPromised ) ;
8
40
@@ -22,25 +54,33 @@ describe('Integration test: custom auth', () => {
22
54
} ) ;
23
55
24
56
it ( 'signs in with custom token' , async ( ) => {
25
- const cred = await signInWithCustomToken ( auth , JSON . stringify ( {
26
- uid : 'custom-uid-yay' ,
27
- claims : { customClaim : 'some-claim' } ,
28
- } ) ) ;
57
+ const cred = await signInWithCustomToken (
58
+ auth ,
59
+ JSON . stringify ( {
60
+ uid : 'custom-uid-yay' ,
61
+ claims : { customClaim : 'some-claim' }
62
+ } )
63
+ ) ;
29
64
expect ( auth . currentUser ) . to . eq ( cred . user ) ;
30
65
expect ( cred . operationType ) . to . eq ( OperationType . SIGN_IN ) ;
31
66
32
- const { user} = cred ;
67
+ const { user } = cred ;
33
68
expect ( user . isAnonymous ) . to . be . false ;
34
69
expect ( user . uid ) . to . eq ( 'custom-uid-yay' ) ;
35
- expect ( ( await user . getIdTokenResult ( false ) ) . claims . customClaim ) . to . eq ( 'some-claim' ) ;
70
+ expect ( ( await user . getIdTokenResult ( false ) ) . claims . customClaim ) . to . eq (
71
+ 'some-claim'
72
+ ) ;
36
73
expect ( user . providerId ) . to . eq ( 'firebase' ) ;
37
74
} ) ;
38
75
39
76
it ( 'uid will overwrite existing user, joining accounts' , async ( ) => {
40
- const { user : anonUser } = await signInAnonymously ( auth ) ;
41
- const customCred = await signInWithCustomToken ( auth , JSON . stringify ( {
42
- uid : anonUser . uid ,
43
- } ) ) ;
77
+ const { user : anonUser } = await signInAnonymously ( auth ) ;
78
+ const customCred = await signInWithCustomToken (
79
+ auth ,
80
+ JSON . stringify ( {
81
+ uid : anonUser . uid
82
+ } )
83
+ ) ;
44
84
45
85
expect ( auth . currentUser ) . to . eq ( customCred . user ) ;
46
86
expect ( customCred . user . uid ) . to . eq ( anonUser . uid ) ;
@@ -54,7 +94,7 @@ describe('Integration test: custom auth', () => {
54
94
beforeEach ( ( ) => {
55
95
email = randomEmail ( ) ;
56
96
customToken = JSON . stringify ( {
57
- uid : email ,
97
+ uid : email
58
98
} ) ;
59
99
} ) ;
60
100
@@ -79,7 +119,10 @@ describe('Integration test: custom auth', () => {
79
119
} ) ;
80
120
81
121
it ( 'account can have email / password attached' , async ( ) => {
82
- const { user : customUser } = await signInWithCustomToken ( auth , customToken ) ;
122
+ const { user : customUser } = await signInWithCustomToken (
123
+ auth ,
124
+ customToken
125
+ ) ;
83
126
await updateEmail ( customUser , email ) ;
84
127
await updatePassword ( customUser , 'password' ) ;
85
128
@@ -94,7 +137,10 @@ describe('Integration test: custom auth', () => {
94
137
} ) ;
95
138
96
139
it ( 'account can be linked using email and password' , async ( ) => {
97
- const { user : customUser } = await signInWithCustomToken ( auth , customToken ) ;
140
+ const { user : customUser } = await signInWithCustomToken (
141
+ auth ,
142
+ customToken
143
+ ) ;
98
144
const cred = EmailAuthProvider . credential ( email , 'password' ) ;
99
145
await linkWithCredential ( customUser , cred ) ;
100
146
await auth . signOut ( ) ;
@@ -109,12 +155,15 @@ describe('Integration test: custom auth', () => {
109
155
110
156
it ( 'account cannot be linked with existing email/password' , async ( ) => {
111
157
await createUserWithEmailAndPassword ( auth , email , 'password' ) ;
112
- const { user : customUser } = await signInWithCustomToken ( auth , customToken ) ;
158
+ const { user : customUser } = await signInWithCustomToken (
159
+ auth ,
160
+ customToken
161
+ ) ;
113
162
const cred = EmailAuthProvider . credential ( email , 'password' ) ;
114
163
await expect ( linkWithCredential ( customUser , cred ) ) . to . be . rejectedWith (
115
164
FirebaseError ,
116
165
'auth/email-already-in-use'
117
166
) ;
118
167
} ) ;
119
168
} ) ;
120
- } ) ;
169
+ } ) ;
0 commit comments