Skip to content

Commit 4553e0c

Browse files
committed
Incorporate observable of loginWithRedirect in observable returned by AuthGuard (#659)
1 parent 81dd79c commit 4553e0c

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ import {
88
UrlSegment,
99
CanActivateChild,
1010
} from '@angular/router';
11-
import { Observable } from 'rxjs';
12-
import { tap, take } from 'rxjs/operators';
11+
import { Observable, of } from 'rxjs';
12+
import { take, switchMap, map } from 'rxjs/operators';
1313
import { AuthService } from './auth.service';
1414

1515
@Injectable({
@@ -40,12 +40,15 @@ export class AuthGuard implements CanActivate, CanLoad, CanActivateChild {
4040
state: RouterStateSnapshot
4141
): Observable<boolean> {
4242
return this.auth.isAuthenticated$.pipe(
43-
tap((loggedIn) => {
43+
switchMap((loggedIn) => {
4444
if (!loggedIn) {
45-
this.auth.loginWithRedirect({
46-
appState: { target: state.url },
47-
});
45+
return this.auth
46+
.loginWithRedirect({
47+
appState: { target: state.url },
48+
})
49+
.pipe(map(() => false));
4850
}
51+
return of(true);
4952
})
5053
);
5154
}

0 commit comments

Comments
 (0)