Skip to content

Commit 9c9319f

Browse files
authored
fix: resolve User is not unauthenticated error seen on logout (#10349)
* fix: do not cache getAuthenticatedUser call * use initialQuery, add back meta tag for initial load of users * lift initialUserData
1 parent ab2904a commit 9c9319f

File tree

2 files changed

+9
-16
lines changed

2 files changed

+9
-16
lines changed

site/src/api/queries/users.ts

+8-15
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ import {
55
GetUsersResponse,
66
UpdateUserPasswordRequest,
77
UpdateUserProfileRequest,
8-
User,
98
UsersRequest,
9+
User,
1010
} from "api/typesGenerated";
11-
import { getMetadataAsJSON } from "utils/metadata";
1211
import { getAuthorizationKey } from "./authCheck";
12+
import { getMetadataAsJSON } from "utils/metadata";
1313

1414
export const users = (req: UsersRequest): UseQueryOptions<GetUsersResponse> => {
1515
return {
@@ -89,21 +89,14 @@ export const authMethods = () => {
8989
};
9090
};
9191

92-
const initialMeData = getMetadataAsJSON<User>("user");
93-
const meKey = ["me"] as const;
92+
const initialUserData = getMetadataAsJSON<User>("user");
9493

95-
export const me = (queryClient: QueryClient) => {
94+
export const me = () => {
9695
return {
97-
queryKey: meKey,
98-
queryFn: async () => {
99-
const cachedData = queryClient.getQueryData(meKey);
100-
if (cachedData === undefined && initialMeData !== undefined) {
101-
return initialMeData;
102-
}
103-
104-
return API.getAuthenticatedUser();
105-
},
106-
} satisfies UseQueryOptions<User>;
96+
queryKey: ["me"],
97+
initialData: initialUserData,
98+
queryFn: API.getAuthenticatedUser,
99+
};
107100
};
108101

109102
export const hasFirstUser = () => {

site/src/components/AuthProvider/AuthProvider.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ const AuthContext = createContext<AuthContextValue | undefined>(undefined);
4646

4747
export const AuthProvider: FC<PropsWithChildren> = ({ children }) => {
4848
const queryClient = useQueryClient();
49-
const meOptions = me(queryClient);
49+
const meOptions = me();
5050

5151
const userQuery = useQuery(meOptions);
5252
const authMethodsQuery = useQuery(authMethods());

0 commit comments

Comments
 (0)