HEX
Server: nginx/1.24.0
System: Linux nowruzgan 6.8.0-57-generic #59-Ubuntu SMP PREEMPT_DYNAMIC Sat Mar 15 17:40:59 UTC 2025 x86_64
User: babak (1000)
PHP: 8.3.6
Disabled: NONE
Upload Files
File: /var/dev/nowruzgan/admin/src/main.ts
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';

import { AppModule } from './app/app.module';
import { environment } from './environments/environment';

import { GenericService } from './app/services/generic.service';
import { User } from './app/data.types';

if (environment.production) {
  enableProdMode();
}

async function loginCheck() {
  // some times tokens add up
  let multipleTokens = /^#+([^#]+)#.*/.exec(window.location.hash);
  if(multipleTokens)
    window.location.hash = '#'+multipleTokens[1];

  if(/^#token=[a-zA-Z\-0-9]*$/.exec(window.location.hash)){
    GenericService.userData.token = window.location.hash.substr(7);
    window.location.hash = '';
  }else
    GenericService.userData.token = localStorage.getItem('token') || undefined;

  if(GenericService.userData.token) {
    let user: any = await fetch(`${environment.apiBase}/user/me`, {headers: {
      'Content-Type': 'application/json',
      'x-token': GenericService.userData.token
    }}).catch((error: any) => false);
    user = await user.json().catch((error: any) => false);

    if(user?.id){
      GenericService.userData.user = new User(user);
      localStorage.setItem('token', GenericService.userData.token);
    }
  }
}

loginCheck().then(_ => {
  platformBrowserDynamic().bootstrapModule(AppModule)
    .catch(err => console.error(err));
});