File tree Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Expand file tree Collapse file tree 2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -196,19 +196,20 @@ export class AccountsClient {
196
196
this . store . dispatch ( loggingIn ( true ) ) ;
197
197
try {
198
198
const res : LoginReturnType = await this . transport . loginWithPassword ( user , password ) ;
199
+ this . store . dispatch ( loggingIn ( false ) ) ;
199
200
await this . storeTokens ( res ) ;
200
201
this . store . dispatch ( setUser ( res . user ) ) ;
201
202
this . options . onSignedInHook ( ) ;
202
203
if ( callback && isFunction ( callback ) ) {
203
204
callback ( ) ;
204
205
}
205
206
} catch ( err ) {
207
+ this . store . dispatch ( loggingIn ( false ) ) ;
206
208
if ( callback && isFunction ( callback ) ) {
207
209
callback ( err ) ;
208
210
}
209
211
throw new AccountsError ( err . message ) ;
210
212
}
211
- this . store . dispatch ( loggingIn ( false ) , user ) ;
212
213
}
213
214
214
215
loggingIn ( ) : boolean {
Original file line number Diff line number Diff line change @@ -212,6 +212,7 @@ describe('Accounts', () => {
212
212
const callback = jest . fn ( ) ;
213
213
await Accounts . loginWithPassword ( 'username' , 'password' , callback ) ;
214
214
expect ( callback . mock . calls . length ) . toEqual ( 1 ) ;
215
+ expect ( Accounts . loggingIn ( ) ) . toBe ( false ) ;
215
216
} ) ;
216
217
it ( 'calls transport' , async ( ) => {
217
218
const loginWithPassword = jest . fn ( ( ) => Promise . resolve ( loggedInUser ) ) ;
@@ -238,6 +239,18 @@ describe('Accounts', () => {
238
239
expect ( callback . mock . calls [ 0 ] [ 0 ] ) . toEqual ( 'error' ) ;
239
240
}
240
241
} ) ;
242
+ it ( 'sets loggingIn flag to false on failed login' , async ( ) => {
243
+ const transport = {
244
+ loginWithPassword : ( ) => Promise . reject ( 'error' ) ,
245
+ } ;
246
+ Accounts . config ( { history } , transport ) ;
247
+ try {
248
+ await Accounts . loginWithPassword ( 'username' , 'password' ) ;
249
+ throw new Error ( ) ;
250
+ } catch ( err ) {
251
+ expect ( Accounts . loggingIn ( ) ) . toBe ( false ) ;
252
+ }
253
+ } ) ;
241
254
it ( 'stores tokens in local storage' , async ( ) => {
242
255
const transport = {
243
256
loginWithPassword : ( ) => Promise . resolve ( loggedInUser ) ,
You can’t perform that action at this time.
0 commit comments