제퍼넷 로고

Firebase 인증을 사용한 GraphiQL | 코멘터

시간

사용중인 경우 GraphiQL IDE 에 의해 제공 헬릭스 GraphQL 서버, Firebase(Google Identity Platform) 인증 흐름과 연결하는 것이 그리 간단하지 않다는 것을 알 수 있습니다.

작동하게 하는 한 가지 방법은 GraphiQL IDE가 포함된 HTML 페이지에 다음 코드 스니펫을 삽입하는 것입니다.

<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>

전체 예제는 다음에서 찾으십시오. https://github.com/kriasoft/relay-starter-kit

spot_img

최신 인텔리전스

spot_img