Skip to content

Commit

Permalink
Fix login redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
marc92w committed Mar 14, 2024
1 parent b87d543 commit 0e809f3
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/main/webapp/src/app/util/auth/authentication.guard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,22 @@ import { AuthTokenProviderService } from './authtokenprovider.service';
* @author mweise
*/
export const loggedIn: (expectedLoggedIn: boolean) => CanActivateFn = (expectedLoggedIn ) => {
return (route) => {
return (_route, state) => {
const router = inject(Router);

const redirect = route.url;
const redirect = state.url;
return inject(AuthTokenProviderService).loggedIn.pipe(
map(actualLoggedIn => {
if (actualLoggedIn === expectedLoggedIn) {
return true;
}
return router.createUrlTree(['/login'], {queryParams: {redirect}});
if (!actualLoggedIn) {
return router.createUrlTree(['/login'], {queryParams: {redirect}});
}
if (redirect !== "/login") {
return router.createUrlTree([redirect]);
}
return router.createUrlTree(["/home"]);
})
);
}
Expand Down

0 comments on commit 0e809f3

Please sign in to comment.