Предотвратите перезагрузку страницы Adal.js 3 раза.Угловой 5 - PullRequest
0 голосов
/ 08 октября 2018

У меня проблема с adal.js.

При первой загрузке моего приложения, когда он не получил токен, adal перезагружает проект дырки 3 раза, поэтому у меня есть все мои запросы httpповторяется.Я пробовал несколько исправлений, но никто не работает.Я использую Angular 5.2.1.

Я вижу в одной из перезагрузок URL с: id_token.

У кого-то есть такая же проблема?Все мои партнеры работают над этим, но без решения ...

У меня есть этот код:

index.html

<!doctype html>
<html lang="en">
<head>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta charset="utf-8">
<title>Santander Global Tech</title>
<base href="./">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://fonts.googleapis.com/css?family=Open+Sans:300,400" rel="stylesheet">
<link rel="preconnect" href="https://graph.microsoft.com" crossorigin/>
<link rel="preconnect" href="https://santandernet.sharepoint.com" crossorigin/>
<link rel="preconnect" href="https://login.microsoftonline.com" crossorigin/>
<link rel="preconnect" href="https://www.google-analytics.com/" crossorigin/>
<link rel="icon" type="image/x-icon" href="favicon.ico" >
<link href="/assets/chatbot/css/botchat.css" rel="stylesheet" />
<link href="/assets/chatbot/css/SamChatBot.web.css" rel="stylesheet" />
<script src="/assets/lib/adal.min.js"></script>
<script src="/assets/chatbot/js/SamChatBotWeb.js"></script>
<script src="/assets/chatbot/js/botchatweb.js"></script>
</head>
 <body>
   <app-root></app-root>
</body>
</html>

app-routing.module.ts

const routes: Routes = [
 { path: '', component: OutletComponent, canActivate: 
 [ConfigGuardService],
  children: [
  { path: '', component: HomeComponent, canActivate: [AuthUserGuard, AuthGuard ],
    children: [
      { path: '', component: DashboardComponent, pathMatch: 'full' },
      { path: 'detalle-noticia/:id', component: NoticeDetailsComponent },
      { path: 'area-comunicacion', loadChildren: './comunication-area/comunication-area.module#ComunicationAreaModule'},
      { path: 'resultados/:string', loadChildren: './search-result/search-result.module#SearchResultModule'},
      { path: 'resultados/detalle-perfil/:persona', loadChildren: './profiles/profiles.module#ProfilesModule'},
      { path: 'herramientas', loadChildren: './tools/tools.module#ToolsModule'},
      { path: 'solicitudes', loadChildren: './allrequests/allrequests.module#AllrequestsModule'},
      { path: '**', redirectTo: ''},
    ]},
   ]
    }
];

@NgModule({
 imports: [RouterModule.forRoot(routes, { useHash: true })],
  exports: [RouterModule],
  providers: [
  ConfigGuardService,
  AuthUserGuard
 ]
})

auth.guard.ts

  canActivate(route: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
  this.adalSrv.context.handleWindowCallback();
if (this.adalSrv.isLogged) {
  return true;
} else {
  this.adalSrv.context.login();

  // Este es el navigate que tiene que funcionar. Tiene que ir al componente "login" pero se queda en bucle y no va al login.
  // Creemos que es por algo del app-routing.module y dónde colocar el componente "login" en la estructura de los path y los children.

  // this.router.navigate(['login'], { queryParams: { returnUrl: state.url } });
  console.log('Logando');
  return false;
 }
}

canActivateChild(childRoute: ActivatedRouteSnapshot, state: RouterStateSnapshot): boolean {
return this.canActivate(childRoute, state);
}
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...