As a workaround to get authentication through a GraphQL API, I've subclassed NbLoginComponent
and overwritten it's login()
method, passing a proper GraphQL request payload to NbAuthService.authenticate()
, e.g.:
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()
})
}