fix: teams edit modal + race conditions on currentUser

This commit is contained in:
Liyas Thomas
2021-05-14 03:40:53 +00:00
committed by GitHub
parent e7dd67deaa
commit 4656d67fcf
8 changed files with 59 additions and 151 deletions

View File

@@ -4,15 +4,27 @@ import { setContext } from "@apollo/client/link/context"
import { fb } from "./fb"
import { getMainDefinition } from "@apollo/client/utilities"
let authToken: String | null = null
export function registerApolloAuthUpdate() {
fb.idToken$.subscribe((token: String | null) => {
console.log(token, "from sub")
authToken = token
})
}
/**
* Injects auth token if available
*/
const authLink = setContext((_, { headers }) => {
if (fb.idToken) {
console.log(authToken)
if (authToken) {
return {
headers: {
...headers,
authorization: `Bearer ${fb.idToken}`,
authorization: `Bearer ${authToken}`,
},
}
} else {
@@ -38,11 +50,11 @@ const wsLink = new WebSocketLink({
reconnect: true,
lazy: true,
connectionParams: () => {
if (fb.idToken) {
if (authToken) {
return {}
} else {
return {
authorization: `Bearer ${fb.idToken}`,
authorization: `Bearer ${authToken}`,
}
}
},

View File

@@ -42,12 +42,14 @@ export const currentUserInfo$ = new BehaviorSubject<UserInfo | null>(null)
/**
* Initializes the currenUserInfo$ view and sets up its update mechanism
*/
export function initUserInfo() {
updateUserInfo()
export async function initUserInfo() {
await updateUserInfo()
console.log("updated")
fb.idToken$.subscribe(token => {
fb.idToken$.subscribe((token) => {
if (token) {
updateUserInfo()
console.log(token, "updateUserInfo")
} else {
currentUserInfo$.next(null)
}
@@ -63,22 +65,24 @@ async function updateUserInfo() {
query: gql`
query GetUserInfo {
me {
uid,
displayName,
email,
photoURL,
uid
displayName
email
photoURL
eaInvited
}
}
`
`,
})
console.log(data)
currentUserInfo$.next({
uid: data.me.uid,
displayName: data.me.displayName,
email: data.me.email,
photoURL : data.me.photoURL,
eaInvited: data.me.eaInvited
photoURL: data.me.photoURL,
eaInvited: data.me.eaInvited,
})
} catch (e) {
currentUserInfo$.next(null)

View File

@@ -32,7 +32,6 @@ export async function getLiveTeamMembersList(apollo, teamID) {
},
})
debugger
subject.next(data.team.members)
const addedSub = apollo
@@ -53,6 +52,7 @@ export async function getLiveTeamMembersList(apollo, teamID) {
},
})
.subscribe(({ data }) => {
console.log(data)
subject.next([...subject.value, data.teamMemberAdded])
})