fix(ui): fix wrong redirects
Changed urlUpdateStrategy from default (deferred) to eager to ensure auth-guard already knows new url before redirecting to keycloak
Changed SignUpService that it saves newContractDetails in sessionStorage using APIMAN_NEW_CONTRACT_DETAILS key to avoid losing data while redirecting
Closes:
MODIFY
src/app/app-routing.module.ts
src/app/app-routing.module.ts
@@ -34,7 +34,7 @@ const routes: Routes = [
];
@NgModule({
- imports: [RouterModule.forRoot(routes)],
+ imports: [RouterModule.forRoot(routes, {urlUpdateStrategy: 'eager'})],
exports: [RouterModule]
})
export class AppRoutingModule {}

MODIFY
src/app/components/plan-card-list/plan-card-list.component.ts
src/app/components/plan-card-list/plan-card-list.component.ts
@@ -25,8 +25,7 @@ export class PlanCardListComponent implements OnInit {
private planService: PlanService,
private policyService: PolicyService,
private signUpService: SignUpService,
- private router: Router,
- private keycloak: KeycloakService
+ private router: Router
) {}
planPoliciesMap = new Map<string, IPolicyExt[]>();
@@ -41,8 +40,6 @@ export class PlanCardListComponent implements OnInit {
}
onSignUp(plan: IApiPlanSummary): void {
- this.checkIfUserIsLoggedIn();
-
const policies: IPolicyExt[] = [];
const planIdVersionMapped = plan.planId + ':' + plan.version;
const foundPlanPolicies = this.planPoliciesMap.get(planIdVersionMapped);
@@ -112,16 +109,4 @@ export class PlanCardListComponent implements OnInit {
}
});
}
-
- /**
- * Checks if the user is logged in and redirects to login if not logged in
- * @private
- */
- private checkIfUserIsLoggedIn(): void {
- void this.keycloak.isLoggedIn().then((loggedIn) => {
- if (!loggedIn) {
- void this.keycloak.login();
- }
- });
- }
}

MODIFY
src/app/guards/auth.guard.ts
src/app/guards/auth.guard.ts
@@ -35,13 +35,8 @@ export class AuthGuard extends KeycloakAuthGuard {
state: RouterStateSnapshot
): Promise<boolean | UrlTree> {
if (!this.authenticated) {
- const url =
- window.location.href.substring(
- 0,
- window.location.href.lastIndexOf('/')
- ) + state.url;
await this.keycloakAngular.login({
- redirectUri: url
+ redirectUri: window.location.href
});
} else {
// we are logged in and can set the tokens

MODIFY
src/app/services/sign-up/sign-up.service.ts
src/app/services/sign-up/sign-up.service.ts
@@ -7,10 +7,11 @@ import { IPolicyExt } from '../../interfaces/IPolicy';
providedIn: 'root'
})
export class SignUpService {
- private signUpInfo: ISignUpInfo = {} as ISignUpInfo;
-
+ private readonly key = 'APIMAN_NEW_CONTRACT_DETAILS';
public getSignUpInfo(): ISignUpInfo {
- return this.signUpInfo;
+ return JSON.parse(
+ window.sessionStorage.getItem(this.key) as string
+ ) as ISignUpInfo;
}
public setSignUpInfo(
@@ -20,12 +21,15 @@ export class SignUpService {
policies: IPolicyExt[],
docsAvailable: boolean
): void {
- this.signUpInfo = {
+ window.sessionStorage.setItem(
+ this.key,
+ JSON.stringify({
apiVersion: apiVersion,
plan: plan,
organizationId: orgId,
policies: policies,
docsAvailable: docsAvailable
- };
+ })
+ );
}
}

fix(ui): fix wrong redirects

Changed urlUpdateStrategy from default (deferred) to eager to ensure auth-guard already knows new url before redirecting to keycloak
Changed SignUpService that it saves newContractDetails in sessionStorage using APIMAN_NEW_CONTRACT_DETAILS key to avoid losing data while redirecting

Closes: #50