mirror of
https://github.com/IT4Change/Ocelot-Social.git
synced 2025-12-13 07:45:56 +00:00
28 lines
719 B
JavaScript
28 lines
719 B
JavaScript
import { request } from 'graphql-request'
|
|
import { GraphQLClient } from 'graphql-request'
|
|
|
|
export const host = 'http://127.0.0.1:3123'
|
|
|
|
export async function getJWT({ email, password }) {
|
|
const mutation = `
|
|
mutation {
|
|
login(email:"${email}", password:"${password}"){
|
|
token
|
|
}
|
|
}`
|
|
const response = await request(host, mutation)
|
|
const { token } = response.login
|
|
if(!token) throw `Could not get a JWT token from the backend:\n${response}`
|
|
return token
|
|
}
|
|
|
|
export async function authenticatedGraphQLClient(params){
|
|
const jwt = await getJWT(params)
|
|
const options = {
|
|
headers: {
|
|
'Authorization': `Bearer ${jwt}`
|
|
}
|
|
}
|
|
return new GraphQLClient(host, options)
|
|
}
|