If you’re using GraphiQL IDE provided by Helix GraphQL server, you may find that it’s not that trivial to hook it up with Firebase (Google Identity Platform) auth flow.
One way to make it work, is to inject the following code snippet into the HTML page containing GraphiQL IDE:
<script type="module"> import { initializeApp, getApp } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-app.js"; import { getAuth } from "https://www.gstatic.com/firebasejs/9.22.0/firebase-auth.js"; const app = initializeApp({ projectId: "${env.GOOGLE_CLOUD_PROJECT}", appId: "${env.FIREBASE_APP_ID}", apiKey: "${env.FIREBASE_API_KEY}", authDomain: "${env.FIREBASE_AUTH_DOMAIN}" }); function setAuthHeader(token) { const editor = document.querySelectorAll('.variable-editor .CodeMirror')[1].CodeMirror; const headers = JSON.parse(editor.getValue()); headers.Authorization = token ? "Bearer " + token : undefined; editor.setValue(JSON.stringify(headers, null, 2)); } getAuth(app).onAuthStateChanged((user) => { if (user) { user.getIdToken().then(token => setAuthHeader(token)); } else { setAuthHeader(null); } });
</script>
Find the full example at https://github.com/kriasoft/relay-starter-kit
- SEO Powered Content & PR Distribution. Get Amplified Today.
- PlatoAiStream. Web3 Data Intelligence. Knowledge Amplified. Access Here.
- Minting the Future w Adryenn Ashley. Access Here.
- Buy and Sell Shares in PRE-IPO Companies with PREIPO®. Access Here.
- Source: https://www.codementor.io/koistya/graphiql-with-firebase-auth-251hx5qhz3
More from Codementor React Fact
Showing a modal dialog with useImperativeHandle() React hook
Source Node: 1778496
Time Stamp: Sep 17, 2022
Intern’s Guide Chat GPT Full Stack: Nest, React, Typescript
Source Node: 1996513
Time Stamp: Mar 6, 2023
Comparing React VS HTMX: Choosing the Right Frontend Approach | Codementor
Source Node: 2144445
Time Stamp: Jun 22, 2023
How to separate logic from UI with React components | by Esmat Ibrahim | Codementor
Source Node: 2116833
Time Stamp: Jun 1, 2023