Skip to content

Open Source Wealth Management Software. Angular + NestJS + Prisma + Nx + TypeScript 🤍

1.2 KB
Raw Blame
import { TokenStorageService } from '@ghostfolio/client/services/token-storage.service';
import { InfoItem } from '@ghostfolio/common/interfaces';
import { NotificationService } from '@ghostfolio/ui/notifications';
import { DataService } from '@ghostfolio/ui/services';

import { ChangeDetectionStrategy, Component } from '@angular/core';
import { Router } from '@angular/router';

@Component({
  changeDetection: ChangeDetectionStrategy.OnPush,
  host: { class: 'page' },
  selector: 'gf-demo-page',
  templateUrl: './demo-page.html'
})
export class GfDemoPageComponent {
  public info: InfoItem;

  public constructor(
    private dataService: DataService,
    private notificationService: NotificationService,
    private router: Router,
    private tokenStorageService: TokenStorageService
  ) {
    this.info = this.dataService.fetchInfo();
  }

  public ngOnInit() {
    const hasToken = !!this.tokenStorageService.getToken();

    if (hasToken) {
      this.notificationService.alert({
        title: $localize`As you are already logged in, you cannot access the demo account.`
      });
    } else {
      this.tokenStorageService.saveToken(this.info.demoAuthToken, true);
    }

    this.router.navigate(['/']);
  }
}