- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用 ngx admin 创建使用 nebular 的管理面板,我按照此文档添加 authGard:
docs
这用于自定义登录:
docs2
我使用的代码:
@NgModule({
declarations: [
AppComponent,
],
providers: [
AuthGuard,
],
imports: [
***
],
bootstrap: [AppComponent],
})
export class AppModule {
}
//**********
@Injectable()
export class AuthGuard implements CanActivate {
constructor(private authService: NbAuthService, private router: Router) {
}
canActivate() {
console.log(this.authService.isAuthenticated());
return this.authService.isAuthenticated()
.pipe(
tap(authenticated => {
if (!authenticated) {
console.log(authenticated);
this.router.navigate(['auth/login']);
}
}),
);
}
}
//**********
const routes: Routes = [
{
path: 'pages',
canActivate: [AuthGuard],
loadChildren: () => import('./pages/pages.module')
.then(m => m.PagesModule),
},
{
path: 'auth',
loadChildren: () => import('./auth/auth.module').then(m => m.NgxAuthModule),
},
{ path: '', redirectTo: 'pages', pathMatch: 'full' },
{ path: '**', redirectTo: 'pages' },
];
最佳答案
问题已解决。
文档说响应应该是这样的:
{
data: {
token: 'some-jwt-token'
}
}
我的回复是:
{
data: {
access_token: 'some-jwt-token'
}
}
并在文档中写入我们可以将( token )更改为其他内容,如下所示:
token: {
key: 'access_token', // this parameter tells where to look for the token
}
但这不是真的,我们应该在 NbAuthModule.forRoot 中使用它:
token: {
key: 'data.access_token',
}
关于javascript - AuthGuard 在星云中总是 false,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60786419/
我有一个 AuthGuard.service.ts 的代码如下。 import { Injectable } from '@angular/core'; import { ActivatedRoute
我想通过检查用户是否从服务器登录但异步函数未执行来保护我的路由 这是我的代码: canActivate (route: ActivatedRouteSnapshot , state: RouterSt
我正在使用 Angular CanActivate Authguard 接口(interface)来保护我的组件。 @Injectable() export class AuthGuard imple
要允许访问管理路由,我必须检查两件事: 如果用户通过身份验证 如果此用户是管理员。我从 firebase 数据库获取管理状态。 管理 guard import {ActivatedRouteSnaps
我在这里阅读了指南:https://angular.io/docs/ts/latest/guide/router.html 看起来很简单,但是,我不确定如何在 auth guard (canActiv
我想创建一个路由防护来保护路由免受未经授权的用户的侵害。 我正在使用 jsonwebtoken 进行授权,目前将其存储在 localStorage 中。 我的想法是,当用户想要访问 protected
我使用 ngx admin 创建使用 nebular 的管理面板,我按照此文档添加 authGard: docs 这用于自定义登录: docs2 所有事情都正常,我收到成功消息: 但我在 autoga
I'm loading a books module with the following routing configuration (src/app/index.ts) -- 请注意,这是一个 s
我正在尝试在 Angular 5 中创建条件路由,我已经看到了这篇文章和 Angular 的官方里程碑页面: Angular2 conditional routing 。 但是我没有找到根据输入变量创
页面刷新后,身份验证似乎不会持续存在。每当我登录时,它都会成功重定向我。但是,当我刷新时,无法再访问。 这是auth guard 路由器 import { BrowserModule } from '
我的应用程序将使用两种不同的身份验证策略 - 一种针对使用浏览器的用户,另一种针对公共(public) API。我将为使用浏览器的用户设置一个 header,然后我的应用程序将根据该 header 的
有没有办法在 authguard 中使用相对路径模式进行重定向? 我试过 @Injectable() export class ServerAuthGuard implements CanActiva
我有这个 AuthGuard: export class AuthGuard implements CanActivate { constructor (private router: Route
尝试遵循此处提供的 AuthGuard 示例: http://www.sparkbit.pl/angular-2-route-guards-real-life-example/ 不幸的是,在尝试实现
在模板组件中AppComponent ,根据值,变量 this.loggedInService.isLoggedIn在 logIn() 之间切换和logout()方法,在应用程序组件 AppCompo
我正在开发一个 Angular 应用程序,它具有以下URL路径, /(根目录) /类(class) /类(class)/创建 /类(class)/:id /验证/登录 我已为除 auth/login
我有一个 ionic 4 应用程序,它本地存储有关用户的信息。当用户打开应用程序时,如果他的信息在那里,那么我希望将他发送到主页。如果他不是,那么我希望他被路由到登录页面,这很正常。 我遇到的问题是,
使用 ASP.NET Core API 应用程序登录到 Angular 应用程序后,出现以下错误 Error: Uncaught (in promise): Error: StaticInjector
我想这是一个很简单的问题,但不幸的是我真的不知道如何处理它。 我正在尝试将我的 UserAuthenticationService 服务与 ActivationGuard 连接。 UserAuthen
我想在以 Angular 授予对特定路由的访问权限之前提供服务器端身份验证。 我有一个实现 CanActivate 的 AuthGuard 和一个服务 AuthService。authService
我是一名优秀的程序员,十分优秀!