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" type="application/javascript"
></script> ></script>
<script> <script>
const root = ReactDOM.createRoot(document.getElementById('graphiql')); if (window.authToken === undefined) {
root.render( const root = ReactDOM.createRoot(document.getElementById('graphiql'));
React.createElement(GraphiQL, { root.render(
fetcher: GraphiQL.createFetcher({ React.createElement(GraphiQL, {
url: '/gql', fetcher: GraphiQL.createFetcher({
headers: { url: '/gql',
"Authorization": "Basic %s", }),
}, defaultEditorToolsVisibility: true,
}), }),
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 ${res}`" + `,
},
}),
defaultEditorToolsVisibility: true,
}),
);
});
}
</script> </script>
</body> </body>
</html> </html>
`, auth_token) `)
w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.WriteHeader(http.StatusOK) w.WriteHeader(http.StatusOK)