akveo / akveo/nebular

auntenticacion with graphql

Aperta
#2,178 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
needs triage
Lingua principale
TypeScript
Stelle
8.1k
Fork
1.5k
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm trying to authenticate with graphql, the server returns my token but NbAuth isn't taking it, I guess because of the kind of response graphql sends

```
import { NbPasswordAuthStrategy, NbAuthJWTToken } from '@nebular/auth';
import { environment } from '../../environments/environment';

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 return:

```
{
"data":{
"login":{ "token":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJkYXRhIjoiYW05eVoyNTJRR2R0WVdsc0xtTnZiUT09IiwiaWF0IjoxNTc5NDA3NjIyLCJleHAiOjE1ODAwMTI0MjJ9.adP0HmrGJPOgtTMudDGX81-E1ScGooe-XRGA_ywnKwI"
}
}
}
```

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.