Skip to content

Commit 76ecb58

Browse files
fix: avoid emitting empty appState for regular login flows
1 parent d63825a commit 76ecb58

2 files changed

Lines changed: 9 additions & 14 deletions

File tree

projects/auth0-angular/src/lib/auth.service.spec.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,7 +1143,7 @@ describe('AuthService', () => {
11431143
});
11441144
});
11451145

1146-
it('should add response_type to appState for regular login', (done) => {
1146+
it('should preserve appState as-is for regular login', (done) => {
11471147
const appState = {
11481148
myValue: 'State to Preserve',
11491149
};
@@ -1158,10 +1158,7 @@ describe('AuthService', () => {
11581158
const localService = createService();
11591159
localService.handleRedirectCallback().subscribe(() => {
11601160
localService.appState$.subscribe((receivedState) => {
1161-
expect(receivedState).toEqual({
1162-
...appState,
1163-
response_type: ResponseType.Code,
1164-
});
1161+
expect(receivedState).toEqual(appState);
11651162
done();
11661163
});
11671164
});

projects/auth0-angular/src/lib/auth.service.ts

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -391,18 +391,16 @@ export class AuthService<TAppState extends AppState = AppState>
391391
if (!isLoading) {
392392
this.authState.refresh();
393393
}
394-
const { appState = {} as TAppState, response_type, ...rest } = result;
394+
const { appState, response_type, ...rest } = result;
395395
const target = appState?.target ?? '/';
396396

397-
// Add response_type to appState
398-
appState.response_type = response_type;
399-
400-
// If this is a connect account flow, add the connected account data to appState
401397
if (response_type === ResponseType.ConnectCode) {
402-
appState.connectedAccount = rest as ConnectedAccount;
403-
}
404-
405-
if (appState) {
398+
this.appStateSubject$.next({
399+
...(appState ?? {}),
400+
response_type,
401+
connectedAccount: rest as ConnectedAccount,
402+
} as TAppState);
403+
} else if (appState) {
406404
this.appStateSubject$.next(appState);
407405
}
408406

0 commit comments

Comments
 (0)