Open-Source API Development Ecosystem • https://hoppscotch.io • Offline, On-Prem & Cloud • Web, Desktop & CLI • Open-Source Alternative to Postman, Insomnia
TypeScript apiapi-clientapi-restapi-testingdeveloper-toolsgraphqlhttphttp-clientpwarestrest-apispatestingtesting-toolstoolsvuevuejswebsocket
Update race condition with Apollo getting ID Token and BackendUserInfo
Andrew Bastine7dd67deaa3c
diff --git a/helpers/apollo.ts b/helpers/apollo.tsindex 195bbac26..74ada4b09 100644--- a/helpers/apollo.ts+++ b/helpers/apollo.ts@@ -4,30 +4,15 @@ import { setContext } from "@apollo/client/link/context"import { fb } from "./fb"import { getMainDefinition } from "@apollo/client/utilities"-/**- * Stores the current authentication token- *- * The token stored here is the Firebase Auth token.- * If null, no token is passed (no user signed in)- */-let authToken: string | null = null--/*- * Updates the token value on Firebase ID Token changes- */-fb.idToken$.subscribe((newToken) => {- authToken = newToken-})-/*** Injects auth token if available*/const authLink = setContext((_, { headers }) => {- if (authToken) {+ if (fb.idToken) {return {headers: {...headers,- authorization: `Bearer ${authToken}`,+ authorization: `Bearer ${fb.idToken}`,},}} else {@@ -53,11 +38,12 @@ const wsLink = new WebSocketLink({reconnect: true,lazy: true,connectionParams: () => {- console.log("WS Authorization")- console.log(authToken)-- return {- authorization: `Bearer ${authToken}`,+ if (fb.idToken) {+ return {}+ } else {+ return {+ authorization: `Bearer ${fb.idToken}`,+ }}},},