- change privateInboxGraphQLClient options

This commit is contained in:
ilya-bkv 2023-11-13 16:41:54 +03:00
parent 04efdd368e
commit b83005fbaa
4 changed files with 14 additions and 2 deletions

View File

@ -99,7 +99,7 @@ export const NotificationsProvider = (props: { children: JSX.Element }) => {
method: 'GET', method: 'GET',
headers: { headers: {
'Content-Type': 'application/json', 'Content-Type': 'application/json',
Authorization: 'Bearer ' + getToken() Authorization: getToken()
}, },
onmessage(event) { onmessage(event) {
const m: SSEMessage = JSON.parse(event.data) const m: SSEMessage = JSON.parse(event.data)

View File

@ -48,5 +48,15 @@ export const privateGraphQLClient = createClient(options)
export const privateInboxGraphQLClient = createClient({ export const privateInboxGraphQLClient = createClient({
...options, ...options,
fetchOptions: () => {
// localStorage is the source of truth for now
// to change token call setToken, for example after login
const token = localStorage.getItem(TOKEN_LOCAL_STORAGE_KEY)
if (!token) {
console.error('[privateInboxGraphQLClient] fetchOptions: token is null!')
}
const headers = { Authorization: token }
return { headers }
},
url: 'https://chat.discours.io' url: 'https://chat.discours.io'
}) })

View File

@ -373,6 +373,7 @@ export const apiClient = {
export const inboxClient = { export const inboxClient = {
loadChats: async (options: QueryLoadChatsArgs): Promise<Chat[]> => { loadChats: async (options: QueryLoadChatsArgs): Promise<Chat[]> => {
const resp = await privateInboxGraphQLClient.query(myChats, options).toPromise() const resp = await privateInboxGraphQLClient.query(myChats, options).toPromise()
console.log('!!! resp:', resp)
return resp.data.loadChats.chats return resp.data.loadChats.chats
}, },

View File

@ -1,6 +1,7 @@
export const isDev = import.meta.env.MODE === 'development' export const isDev = import.meta.env.MODE === 'development'
const defaultApiUrl = 'https://testapi.discours.io' const defaultApiUrl = 'https://testapi.discours.io'
export const apiBaseUrl = import.meta.env.PUBLIC_API_URL || defaultApiUrl // export const apiBaseUrl = import.meta.env.PUBLIC_API_URL || defaultApiUrl
export const apiBaseUrl = 'https://v2.discours.io'
export const SENTRY_DSN = import.meta.env.PUBLIC_SENTRY_DSN || '' export const SENTRY_DSN = import.meta.env.PUBLIC_SENTRY_DSN || ''