I’m using AuthConnect (@ionic-enterprise/auth v4.0.0) for authentication. I followed these steps: Getting Started with Auth Connect in @ionic/angular - Auth Connect
Use case:
- A user is trying to log in and the Auth0 popup opens. They enter their credentials and gets redirected to the login page.
- They are blocked from accessing the home page because they need to fill in the sign up form first (expected behaviour). In my code, we’re in the catch block.
- Still on the login page, another user wants to log in by clicking the “Sign Up/Login” button but can’t because the Auth0 popup opens, is automatically authenticating the first user then close. The last user’s credentials are still saved, I believe, in a cookie.
How to completely clear the first user’s data on login error?
On the last version of @ionic-enterprise/auth I called logout() in the catch block but now it seems to be impossible because by following the docs above, “authResult” need to NOT be null in order to logout a user which isn’t the case here. “authResult” is null so I cannot force logout a user anymore.
async login(): Promise<void> {
try {
await this._initialize();
const authResult = await AuthConnect.login(this._provider, this._providerOptions);
const userUuid = jwt_decode(authResult.accessToken)['sub'];
if (userUuid) {
await this._saveAuthResult(authResult);
this.store.dispatch(actionGetUserInfo({ payload: { uuid: userUuid } }));
if (this._userId) {
this.router.navigate([`/${RouterLinkConstant.ROUTE_HOME}`]);
} else if (isNull(this._userId)) {
// Force new user to fill out their personal information if they click on "Sign Up/Login" button
this.router.navigate([`/${RouterLinkConstant.ROUTE_SIGN_UP}`]);
}
}
} catch (err) {
console.error(`[Authentication] ${err}`);
// logout(); is not working here
this._onLoginError(err);
}
}
async logout(): Promise<void> {
try {
await this._initialize();
const authResult = await this.getAuthResult();
if (authResult) {
await AuthConnect.logout(this._provider, authResult);
await this._saveAuthResult(null);
await this.router.navigate([`/${RouterLinkConstant.ROUTE_LANDING}`]);
}
} catch (err) {
console.error(`[Authentication] ${err}`);
}
}