Reputation: 349
A couple of days ago I faced an issue related to the 404 page instead of the Login page. For some reason, it happened immediately after I decided to customize AuthHttpHeaderService and it does not relate to the code base that I wrote, but just for example here is the code snippet
@Injectable({
providedIn: "root",
})
export class CustomAuthHttpHeaderService extends AuthHttpHeaderService {
constructor(
protected override authService: AuthService,
protected override authStorageService: AuthStorageService,
protected override oAuthLibWrapperService: OAuthLibWrapperService,
protected override routingService: RoutingService,
protected override globalMessageService: GlobalMessageService,
protected occEndpointsService: OccEndpointsService,
protected override authRedirectService: AuthRedirectService,
private ssoAuth: SSOAuth,
private authHelperService: AuthHelperService
) {
super(
authService,
authStorageService,
oAuthLibWrapperService,
routingService,
occEndpointsService,
globalMessageService,
authRedirectService
);
}
override handleExpiredRefreshToken(): void {
this.ssoAuth
.getAccessTokenSilently()
.pipe(
filter((token) => !!token),
switchMap((token) => this.authHelperService.loginToSSOAndSAP(token)),
switchMap(() => this.ssoAuth.loginWithRedirect()),
catchError((err) => {
this.authService.coreLogout().finally(() => {
this.routingService.go({ cxRoute: "login" });
this.globalMessageService.add(
{
key: "httpHandlers.sessionExpired",
},
GlobalMessageType.MSG_TYPE_ERROR
);
});
return EMPTY;
})
)
.subscribe();
}
}
Also, I had added this class to the AppModule
{ provide: AuthHttpHeaderService, useClass: CustomAuthHttpHeaderService, }
And here is the magic that comes. When I login with one user and then decide to logout and login with another user, sometimes instead of Login page the user saw 404 page. Here I have to be clear, we are using SSO and when we login it navigates us back to the Login page. The request for the basesites https://{our_website_name_here}/occ/v2/basesites?fields=FULL&lang=en&curr=USD was done first but it looks like the application do not wait for the response and make a new call for the login page - https://{our_website_name_here}/occ/v2/cms/pages?pageType=ContentPage&pageLabelOrId=%2Flogin&lang=en&curr=USD. As you can see the uid of the basesite is missing between "v2" and "cms". But the next request to the Not found page was with all needed information - https://{our_website_name_here}/occ/v2/{our_basesite_uid_here}/cms/pages?pageType=ContentPage&pageLabelOrId=%2Fnot-found&lang=en&curr=USD. So here is the question... Why and how I could handle this situation? Just to be clear, without the implementation of this class, all other things work perfectly.
Here is the screenshot for a better understanding.
There response from the server is the following:
[ { "message": "Base site cms doesn't exist", "type": "InvalidResourceError" } ]
What ever I try to do, but the issue is still in place. And only when I implement this class AuthHttpHeaderService. If even I will just extend it and leave it empty, still the issue will be in place.
Upvotes: 1
Views: 96