diff --git a/apps/callcenter b/apps/callcenter index 24c42fac8f6..429da4b1e7a 160000 --- a/apps/callcenter +++ b/apps/callcenter @@ -1 +1 @@ -Subproject commit 24c42fac8f643683132e371f19e9a2b3b2e69995 +Subproject commit 429da4b1e7a744bfab6ff3618819184f22e52f25 diff --git a/apps/condo/domains/common/utils/next/apollo.ts b/apps/condo/domains/common/utils/next/apollo.ts index cc50df70332..b0348133b1a 100644 --- a/apps/condo/domains/common/utils/next/apollo.ts +++ b/apps/condo/domains/common/utils/next/apollo.ts @@ -43,11 +43,7 @@ const cacheConfig: InitCacheConfig = (cacheOptions) => { } } -function getApiUrl (): string { - return apolloGraphQLUrl -} - export const apolloHelperOptions = { - uri: getApiUrl, + uri: apolloGraphQLUrl, cacheConfig, -} \ No newline at end of file +} diff --git a/packages/next/auth.tsx b/packages/next/auth.tsx index 6cb389b42f8..02f0ab51417 100644 --- a/packages/next/auth.tsx +++ b/packages/next/auth.tsx @@ -2,7 +2,7 @@ import { DocumentNode } from 'graphql' import { gql } from 'graphql-tag' import get from 'lodash/get' import { NextPage } from 'next' -import React, { createContext, useContext, useEffect, useState, useCallback } from 'react' +import React, { createContext, useContext, useEffect, useState, useCallback, useMemo } from 'react' import { DEBUG_RERENDERS, DEBUG_RERENDERS_BY_WHY_DID_YOU_RENDER, preventInfinityLoop, getContextIndependentWrappedInitialProps } from './_utils' import { useApolloClient, useMutation, useQuery } from './apollo' @@ -263,7 +263,7 @@ const AuthProvider: React.FC = ({ children }) => { const { data, loading: userLoading, refetch } = useQuery(USER_QUERY) - const [user, setUser] = useState(get(data, 'authenticatedUser', null)) + const user = useMemo(() => get(data, 'authenticatedUser' || null), [data]) const refetchAuth = useCallback(async () => { await refetch() @@ -277,7 +277,6 @@ const AuthProvider: React.FC = ({ children }) => { if (item) { await apolloClient.clearStore() - setUser(item) } }, onError: (error) => { @@ -286,24 +285,21 @@ const AuthProvider: React.FC = ({ children }) => { }) const [signOutMutation, { loading: signOutLoading }] = useMutation(SIGNOUT_MUTATION, { - onCompleted: async (data) => { - const success = get(data, ['unauthenticateUser', 'success']) - if (success) setUser(null) - + onCompleted: async () => { removeCookieEmployeeId() - await apolloClient.clearStore() + await apolloClient.cache.reset() + apolloClient.cache.writeQuery({ + query: USER_QUERY, + data: { + authenticatedUser: null, + }, + }) }, onError: (error) => { console.error(error) }, }) - useEffect(() => { - if (!userLoading) { - setUser(get(data, 'authenticatedUser', null)) - } - }, [data, userLoading]) - return ( = ({ if (auth.isLoading) return if (!auth.user && activeEmployee !== null) { setActiveEmployee(null) + setActiveEmployeeId(null) } }, [auth.user])