123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- import { BehaviorSubject } from "rxjs"
- import gql from "graphql-tag"
- import { authIdToken$ } from "../fb/auth"
- import { apolloClient } from "../apollo"
- export interface UserInfo {
-
- uid: string
-
- displayName: string | null
-
- email: string | null
-
- photoURL: string | null
-
- eaInvited: boolean
- }
- export const currentUserInfo$ = new BehaviorSubject<UserInfo | null>(null)
- export function initUserInfo() {
- authIdToken$.subscribe((token) => {
- if (token) {
- updateUserInfo()
- } else {
- currentUserInfo$.next(null)
- }
- })
- }
- async function updateUserInfo() {
- try {
- const { data } = await apolloClient.query({
- query: gql`
- query GetUserInfo {
- me {
- uid
- displayName
- email
- photoURL
- eaInvited
- }
- }
- `,
- })
- currentUserInfo$.next({
- uid: data.me.uid,
- displayName: data.me.displayName,
- email: data.me.email,
- photoURL: data.me.photoURL,
- eaInvited: data.me.eaInvited,
- })
- } catch (e) {
- currentUserInfo$.next(null)
- }
- }
|