如何在Node.js中设置Admin令牌的到期时间?

时间:2019-06-13 20:25:02

标签: node.js angular typescript

我的app.routing.ts中有管理URL,并已用Adminguard.ts保护了它。我想将令牌过期设置为几分钟,但是每当我想打开管理页面或刷新它时,都会遇到问题。它总是重定向到auth / login。这是我在 app.routing.ts

中的管理路线
import { NgModule } from '@angular/core';
import { RouterModule, Routes } from '@angular/router';
import { EventListComponent } from './events/event-list/event-list.component';
import { EventCreateComponent } from './events/event-create/event-create.component';
import { AuthGuard } from './auth/auth.guard';
import {AdminGuard} from './auth/admin.guard';
import { EventDetailsComponent } from './events/event-details/event-details.component';
import { EventListAllComponent } from './events/event-list-all/event-list-all.component';
import { ChatComponent } from './chat/chat.component';
import { UsersComponent } from './users/users.component';
import { AdminComponent } from './admin/admin.component';
import { DatatableslibraryComponent } from './admin/datatables/datatables.component';
import { EventsComponent } from './admin/events/events.component';
import {ApproveComponent} from './admin/approve/approve.component';
const routes: Routes = [
  { path: 'admin', component: AdminComponent,canActivate: [AdminGuard]},
   { path: 'users/:eventId', component: UsersComponent,canActivate: [AuthGuard] },
    { path: 'use1', component:DatatableslibraryComponent,canActivate: [AdminGuard]},
    { path: 'use2', component:EventsComponent,canActivate: [AdminGuard] }
];
@NgModule({
  imports: [RouterModule.forRoot(routes)],
  exports: [RouterModule],
  providers: [AuthGuard,AdminGuard]
})
export class AppRoutingModule {}

这是我存储用户会话的功能。我想对Admin做同样的事情。

autoAuthUser() {
    const authInformation = this.getAuthData();
    if (!authInformation) {
      return;
    }
    const now = new Date();
    const expiresIn = authInformation.expirationDate.getTime() - now.getTime();
    if (expiresIn > 0) {
      this.token = authInformation.token;
      this.isAuthenticated = true;
      this.userId = authInformation.userId;
      this.setAuthTimer(expiresIn / 1000);
      this.authStatusListener.next(true);
    }
  }

任何人都可以告诉我如何存储会话或为我的管理页面设置令牌到期,以便再次将其重定向到同一管理页面吗?

0 个答案:

没有答案