Updated graphiql handler to use authToken() where available

gql_cataclysm
noah metz 2023-10-10 22:25:12 -06:00
parent 0a936f50f8
commit c4de49099b
1 changed files with 26 additions and 12 deletions

@ -235,22 +235,36 @@ func GraphiQLHandler(auth_token string) func(http.ResponseWriter, *http.Request)
type="application/javascript"
></script>
<script>
if (window.authToken === undefined) {
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
root.render(
React.createElement(GraphiQL, {
fetcher: GraphiQL.createFetcher({
url: '/gql',
}),
defaultEditorToolsVisibility: true,
}),
);
} else {
authToken().then(function(res){
const root = ReactDOM.createRoot(document.getElementById('graphiql'));
root.render(
React.createElement(GraphiQL, {
fetcher: GraphiQL.createFetcher({
url: '/gql',
headers: {
"Authorization": "Basic %s",
"Authorization": ` + "`Basic ${res}`" + `,
},
}),
defaultEditorToolsVisibility: true,
}),
);
});
}
</script>
</body>
</html>
`, auth_token)
`)
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK)