super-graph Malheureusement, super-graph n'a pas tenu les promesses qu'il semblait annoncer. Je propose donc de basculer sur un serveur Go classique (via goweb). L'authentification OpenID Connect étant gérée côté backend et non plus côté frontend.
43 lines
885 B
TypeScript
43 lines
885 B
TypeScript
import { GraphQLClient } from 'graphql-request'
|
|
import { Config } from "../config";
|
|
|
|
export class UnauthorizedError extends Error {
|
|
constructor(...args: any[]) {
|
|
super(...args)
|
|
Object.setPrototypeOf(this, UnauthorizedError.prototype);
|
|
}
|
|
}
|
|
|
|
export class DaddyClient {
|
|
|
|
gql: GraphQLClient
|
|
|
|
constructor(endpoint: string) {
|
|
this.gql = new GraphQLClient(endpoint, {
|
|
headers: {
|
|
mode: 'cors',
|
|
}
|
|
});
|
|
}
|
|
|
|
fetchUser(email: string) {
|
|
return this.gql.rawRequest(`
|
|
query fetchUser {
|
|
user(where: {email: {eq: $email}}) {
|
|
id
|
|
created_at
|
|
updated_at
|
|
email,
|
|
full_name
|
|
}
|
|
}
|
|
`, { email })
|
|
.then(this.assertAuthorization)
|
|
}
|
|
|
|
assertAuthorization({ status, data }: any) {
|
|
if (status === 401) return Promise.reject(new UnauthorizedError());
|
|
return data;
|
|
}
|
|
|
|
} |