Skip to content

Commit

Permalink
Execute autoregistration component only in client side
Browse files Browse the repository at this point in the history
  • Loading branch information
milanmajchrak committed Dec 5, 2024
1 parent 1cc31c6 commit 155d56f
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div *ngIf="(showAttributes | async) == true" class="container" >
<div *ngIf="isBrowser && (showAttributes | async) == true" class="container" >
<div *ngIf="(verificationToken$ | async) != null">
<h5 class="display-4">{{'clarin.autoregistration.welcome.message' | translate}} {{dspaceName$ | async}}</h5>
<div class="alert alert-info" role="alert" style="width: 100%">
Expand Down
44 changes: 28 additions & 16 deletions src/app/login-page/autoregistration/autoregistration.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { Component, Inject, OnInit, PLATFORM_ID } from '@angular/core';
import { GetRequest, PostRequest } from '../../core/data/request.models';
import {
getFirstCompletedRemoteData, getFirstSucceededRemoteData,
Expand Down Expand Up @@ -27,6 +27,7 @@ import { getBaseUrl } from '../../shared/clarin-shared-util';
import { ConfigurationProperty } from '../../core/shared/configuration-property.model';
import { RemoteData } from '../../core/data/remote-data';
import { HardRedirectService } from '../../core/services/hard-redirect.service';
import { isPlatformBrowser } from '@angular/common';

/**
* This component is showed up when the user has clicked on the `verification token`.
Expand Down Expand Up @@ -72,7 +73,13 @@ export class AutoregistrationComponent implements OnInit {
*/
showAttributes: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(false);

constructor(public route: ActivatedRoute,
/**
* Flag to check if the code is executed on the client side.
*/
isBrowser: boolean;

constructor(@Inject(PLATFORM_ID) private platformId: object,
public route: ActivatedRoute,
private requestService: RequestService,
protected halService: HALEndpointService,
protected rdbService: RemoteDataBuildService,
Expand All @@ -82,23 +89,28 @@ export class AutoregistrationComponent implements OnInit {
private verificationTokenService: ClarinVerificationTokenDataService,
private store: Store<CoreState>,
private hardRedirectService: HardRedirectService
) { }
) {
this.isBrowser = isPlatformBrowser(this.platformId);
}

async ngOnInit(): Promise<void> {
// Retrieve the token from the request param
this.verificationToken = this.route?.snapshot?.queryParams?.['verification-token'];
// Load the repository name for the welcome message
this.loadRepositoryName();
// Load the `ClarinVerificationToken` based on the `verificationToken` value
this.loadVerificationToken();
await this.assignBaseUrl();
await this.loadShowAttributes().then((value: RemoteData<ConfigurationProperty>) => {
const stringBoolean = value?.payload?.values?.[0];
this.showAttributes.next(stringBoolean === 'true');
});
if (this.isBrowser) {
// Only execute client-side logic
// Retrieve the token from the request param
this.verificationToken = this.route?.snapshot?.queryParams?.['verification-token'];
// Load the repository name for the welcome message
this.loadRepositoryName();
// Load the `ClarinVerificationToken` based on the `verificationToken` value
this.loadVerificationToken();
await this.assignBaseUrl();
await this.loadShowAttributes().then((value: RemoteData<ConfigurationProperty>) => {
const stringBoolean = value?.payload?.values?.[0];
this.showAttributes.next(stringBoolean === 'true');
});

if (this.showAttributes.value === false) {
this.autologin();
if (this.showAttributes.value === false) {
this.autologin();
}
}
}

Expand Down

0 comments on commit 155d56f

Please sign in to comment.