'How to show login page by default after logout?
I want to show my login screen after logout.
Currently without LogoutModule after logout my page is redirecting to a blank screen and if I implement it as per the documentation, it redirects to homepage.
Documentation reference: https://sap.github.io/spartacus/modules/LogoutModule.html
@NgModule({
imports: [
PageLayoutModule,
RouterModule.forChild([
{
path: null,
canActivate: [LogoutGuard, CmsPageGuard],
component: PageLayoutComponent,
data: { cxRoute: 'logout' },
},
]),
],
})
I have tried protecting my homepage, however if I do that, I am unable to logout at all i.e. nothing is happening if I click logout.
Solution 1:[1]
You can achieve this by overriding the default getRedirectUrl
from LogoutGuard.
Currently, the base class redirects to login page upon logout if and only if it's a closed shop. Meaning, the user must login before doing any action (early login).
An example of how to override the LogoutGuard behavior is to do the following:
1 - create your custom logout guard
@Injectable({
providedIn: 'root',
})
export class NewLogoutGuard extends LogoutGuard {
constructor(
auth: AuthService,
cms: CmsService,
semanticPathService: SemanticPathService,
protectedRoutes: ProtectedRoutesService,
router: Router,
authRedirectService: AuthRedirectService
) {
super(
auth,
cms,
semanticPathService,
protectedRoutes,
router,
authRedirectService
);
}
protected getRedirectUrl(): UrlTree {
return this.router.parseUrl(this.semanticPathService.get('login'));
}
}
2 - aliasing the class providers by providing the new logout guard
{ provide: LogoutGuard, useExisting: NewLogoutGuard },
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | BrianGJ |