如何在ngx-admin/ GraphQL应用程序中通过Nebular进行身份验证?
我发现可用的AuthStrategy
类是有限的,并且没有直接的方法来改变它们的行为。最接近的是NbPasswordAuthStrategy
,它做一个超文本传输协议请求,但是我还没有想出如何在GraphQL应用程序接口中使用它。
发布于 2019-02-06 14:05:33
目前,无法通过GraphQL
进行开箱即用的身份验证。为了解决这个问题,你需要创建一个像NbPasswordAuthStrategy
这样的新策略,但是你的新策略将使用GraphQL
客户端而不是感叹HttpClient
发出请求。
发布于 2019-02-07 21:02:40
作为通过GraphQL应用程序接口进行身份验证的一种变通方法,我对NbLoginComponent
进行了子类化并覆盖了它的login()
方法,将适当的GraphQL请求有效负载传递给NbAuthService.authenticate()
,例如:
login(): void {
this.errors = []
this.messages = []
this.submitted = true
const data = {
variables: this.user,
query: 'mutation($username: String!, $password: String!) { login(username: $username, password: $password) { token } }',
}
this.service.authenticate(this.strategy, data).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(redirect)
}, this.redirectDelay)
}
this.cd.detectChanges()
})
}
https://stackoverflow.com/questions/54465752
复制相似问题