NbAuthModule.forRoot({
strategies: [
NbPasswordAuthStrategy.setup({
name: 'auth',
token: {
class: NbAuthJWTToken,
key: 'token',
},
baseEndpoint: '/api/',
login: {
alwaysFail: false,
endpoint: 'Login',
method: 'get',
redirect: {
success: '/pages',
failure: '/register',
},
},
register: {
endpoint: 'register',
method: 'post',
},
}),
],
forms: {
login: {
redirectDelay: 0, // delay before redirect after a successful login, while success message is shown to the user
strategy: 'auth', // strategy id key.
rememberMe: false, // whether to show or not the `rememberMe` checkbox
showMessages: { // show/not show success/error messages
success: false,
error: true,
}, // social links at the bottom of a page
},
},
}),
我已经制定了这个密码策略来调用我的Asp.net Web Api项目,我还设置了代理服务器,如下所示
{
"/api": {
"target": "http://localhost:54575",
"secure": false
}
}
预期行为:我期望它调用我的api并返回auth token,并将url更改为dashboard,但它的url没有更改。
发布于 2018-11-10 04:33:06
Setup your NbPasswordAuthStrategy in your app.module:
...NbAuthModule.forRoot({
strategies: [
NbPasswordAuthStrategy.setup({
name: 'email',
baseEndpoint: 'auth/',
login: {
endpoint: 'sign-in',
},
register: {
endpoint: 'sign-up',
},
logout: {
endpoint: 'sign-out',
},
token: {
class: NbAuthJWTToken,
key: 'token',
},
}),
],
forms: {
login: {
socialLinks: socialLinks,
},
register: {
socialLinks: socialLinks,
},
},
}).providers,
和您的登录组件:
constructor(protected service: NbAuthService) {
}
login(): void {
this.errors = [];
this.messages = [];
this.submitted = true;
this.service.authenticate(this.strategy, this.user).subscribe((result: NbAuthResult) => {
this.submitted = false;
if (result.isSuccess()) {
this.messages = result.getMessages();
} else {
this.errors = result.getErrors();
}
const redirect = result.getRedirect();
if (redirect) {
setTimeout(() => {
return this.router.navigateByUrl('dashboard');
}, this.redirectDelay);
}
this.cd.detectChanges();
});
}
完整的登录组件:https://github.com/akveo/nebular/tree/master/src/framework/auth/components/login
在导航中,您可以设置成功登录后要转到的位置。目前,它是主页。
发布于 2019-06-13 21:09:42
如果登录失败,则需要返回http错误400。不仅仅是一个安全的:假的。
https://stackoverflow.com/questions/52853644
复制相似问题