File tree Expand file tree Collapse file tree 5 files changed +32
-5
lines changed
packages-exp/auth-exp/src Expand file tree Collapse file tree 5 files changed +32
-5
lines changed Original file line number Diff line number Diff line change @@ -25,6 +25,7 @@ export interface SignInWithIdpRequest {
2525 sessionId ?: string ;
2626 tenantId ?: string ;
2727 returnSecureToken : boolean ;
28+ returnIdpCredential ?: boolean ;
2829 idToken ?: IdToken ;
2930 autoCreate ?: boolean ;
3031 pendingToken ?: string ;
Original file line number Diff line number Diff line change @@ -120,6 +120,27 @@ describe('api/_performApiRequest', () => {
120120 expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
121121 } ) ;
122122
123+ it ( 'should translate server success with errorMessage into auth error' , async ( ) => {
124+ const response = {
125+ errorMessage : ServerError . FEDERATED_USER_ID_ALREADY_LINKED ,
126+ idToken : 'foo-bar'
127+ } ;
128+ const mock = mockEndpoint ( Endpoint . SIGN_IN_WITH_IDP , response , 200 ) ;
129+ const promise = _performApiRequest < typeof request , typeof serverResponse > (
130+ auth ,
131+ HttpMethod . POST ,
132+ Endpoint . SIGN_IN_WITH_IDP ,
133+ request
134+ ) ;
135+ await expect ( promise )
136+ . to . be . rejectedWith ( FirebaseError , 'auth/credential-already-in-use' )
137+ . eventually . with . deep . property ( 'customData' , {
138+ appName : 'test-app' ,
139+ _tokenResponse : response
140+ } ) ;
141+ expect ( mock . calls [ 0 ] . request ) . to . eql ( request ) ;
142+ } ) ;
143+
123144 it ( 'should translate complex server errors to auth errors' , async ( ) => {
124145 const mock = mockEndpoint (
125146 Endpoint . SIGN_UP ,
Original file line number Diff line number Diff line change @@ -132,10 +132,11 @@ export async function _performFetchWithErrorHandling<V>(
132132 throw makeTaggedError ( auth , AuthErrorCode . NEED_CONFIRMATION , json ) ;
133133 }
134134
135- if ( response . ok ) {
135+ if ( response . ok && ! ( 'errorMessage' in json ) ) {
136136 return json ;
137137 } else {
138- const serverErrorCode = json . error . message . split ( ' : ' ) [ 0 ] as ServerError ;
138+ const errorMessage = response . ok ? json . errorMessage : json . error . message ;
139+ const serverErrorCode = errorMessage . split ( ' : ' ) [ 0 ] as ServerError ;
139140 if ( serverErrorCode === ServerError . FEDERATED_USER_ID_ALREADY_LINKED ) {
140141 throw makeTaggedError (
141142 auth ,
Original file line number Diff line number Diff line change @@ -82,7 +82,8 @@ describe('core/strategies/idb', () => {
8282 postBody : 'post-body' ,
8383 tenantId : 'tenant-id' ,
8484 pendingToken : 'pending-token' ,
85- returnSecureToken : true
85+ returnSecureToken : true ,
86+ returnIdpCredential : true
8687 } ) ;
8788 } ) ;
8889
@@ -136,7 +137,8 @@ describe('core/strategies/idb', () => {
136137 postBody : 'post-body' ,
137138 tenantId : 'tenant-id' ,
138139 pendingToken : 'pending-token' ,
139- returnSecureToken : true
140+ returnSecureToken : true ,
141+ returnIdpCredential : true
140142 } ) ;
141143 } ) ;
142144
@@ -193,6 +195,7 @@ describe('core/strategies/idb', () => {
193195 tenantId : 'tenant-id' ,
194196 pendingToken : 'pending-token' ,
195197 returnSecureToken : true ,
198+ returnIdpCredential : true ,
196199 idToken : idTokenBeforeLink
197200 } ) ;
198201 } ) ;
Original file line number Diff line number Diff line change @@ -71,7 +71,8 @@ class IdpCredential extends AuthCredential {
7171 postBody : this . params . postBody || null ,
7272 tenantId : this . params . tenantId ,
7373 pendingToken : this . params . pendingToken ,
74- returnSecureToken : true
74+ returnSecureToken : true ,
75+ returnIdpCredential : true
7576 } ;
7677
7778 if ( idToken ) {
You can’t perform that action at this time.
0 commit comments