Skip to content

Commit

Permalink
Merge pull request #176 from cinovo/bugfix/login-redirect
Browse files Browse the repository at this point in the history
Fix login redirect
  • Loading branch information
YukiInu authored Mar 14, 2024
2 parents b87d543 + 0e809f3 commit 983be5d
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 983be5d

Please sign in to comment.