我正在尝试使用graphql执行身份验证,服务器返回了令牌,但NbAuth没有使用它,我猜是根据发送graphql的响应类型,因为它是Auth期望的不同格式,或者可以通过graphql进行身份验证的另一种方式,可以帮助我添加它们
export const socialLinks = [
{
url: 'https://github.com/akveo/nebular',
target: '_blank',
icon: 'github',
},
{
url: 'https://www.facebook.com/akveo/',
target: '_blank',
icon: 'facebook',
},
{
url: 'https://twitter.com/akveo_inc',
target: '_blank',
icon: 'twitter',
},
];
export const authOptions = {
strategies: [
NbPasswordAuthStrategy.setup({
name: 'email',
baseEndpoint: environment.apiUrl,
token: {
class: NbAuthJWTToken,
key: 'token',
},
login: {
endpoint: '/',
method: 'post',
},
register: {
endpoint: '/auth/sign-up',
method: 'post',
},
logout: {
endpoint: '/auth/sign-out',
method: 'post',
},
requestPass: {
endpoint: '/auth/request-pass',
method: 'post',
},
resetPass: {
endpoint: '/auth/reset-pass',
method: 'post',
},
}),
],
forms: {
login: {
socialLinks: socialLinks,
},
register: {
socialLinks: socialLinks,
},
},
login(): void {
this.user = this.loginForm.value;
this.errors = []
this.messages = []
this.submitted = true
const data = {
variables: {
input: {
email: email,
passwordHash: pass
}
},
query: 'mutation login($input: LoginInput) { login(input: $input){ token } }',
}
this.service.authenticate(this.strategy, data).subscribe((result: NbAuthResult) => {
this.submitted = false
console.log(result)
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()
})
}
Graphql返回:
{
"data":{
"login":{ "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiYW05eVoyNTJRR2R0WVdsc0xtTnZiUT09IiwiaWF0IjoxNTc5NDA3NjIyLCJleHAiOjE1ODAwMTI0MjJ9.adP0HmrGJPOgtTMudDGX81-E1ScGooe-XRGA_ywnKwI"
}
}
}