1- import { getClient } from '../graphql/ServerClient'
1+ import { getGlobalClient } from '../graphql/ServerClient'
22import { MUTATION_UPDATE_PROFILE , QUERY_GET_USERNAME_BY_UUID } from '../graphql/gql/users'
33import { updateUser } from './ManagementClient'
44import { Username } from '../types'
5+
56export interface UpdateUsernameInput {
67 userUuid : string
78 username : string
@@ -14,18 +15,17 @@ interface InitializeUserInDBParams extends UpdateUsernameInput {
1415 auth0UserId : string
1516}
1617
17- const serverClient = getClient ( )
18-
1918/**
2019 * Look up in our db (not Auth0) to see whether a user by uuid exists. If it doesn't then insert a new user profile.
2120 */
2221export const initializeUserInDB = async ( params : InitializeUserInDBParams ) : Promise < boolean > => {
2322 const { auth0UserId, accessToken, userUuid, username, email, avatar } = params
24- const existed = await doesUserByUuidExist ( userUuid )
23+ const client = getGlobalClient ( )
24+ const existed = await doesUserByUuidExist ( client , userUuid )
2525 if ( existed != null ) {
2626 return false
2727 }
28- const res = await serverClient . mutate < { updateUserProfile ?: boolean } , UpdateUsernameInput > ( {
28+ const res = await client . mutate < { updateUserProfile ?: boolean } , UpdateUsernameInput > ( {
2929 mutation : MUTATION_UPDATE_PROFILE ,
3030 variables : {
3131 userUuid,
@@ -52,8 +52,8 @@ export const initializeUserInDB = async (params: InitializeUserInDBParams): Prom
5252 return success
5353}
5454
55- const doesUserByUuidExist = async ( userUuid : string ) : Promise < Username | null > => {
56- const res = await serverClient . query < { getUsername ?: Username } , { userUuid : string } > ( {
55+ const doesUserByUuidExist = async ( client : ReturnType < typeof getGlobalClient > , userUuid : string ) : Promise < Username | null > => {
56+ const res = await client . query < { getUsername ?: Username } , { userUuid : string } > ( {
5757 query : QUERY_GET_USERNAME_BY_UUID ,
5858 variables : {
5959 userUuid
0 commit comments