Skip to content

Fix undefined user causes <Login> to be renderd #18677

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 6 additions & 11 deletions components/dashboard/src/hooks/use-user-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* See License.AGPL.txt in the project root for license information.
*/

import { useContext, useEffect } from "react";
import { useContext } from "react";
import { UserContext } from "../user-context";
import { getGitpodService } from "../service/service";
import { trackLocation } from "../Analytics";
Expand All @@ -19,7 +19,7 @@ export const useUserLoader = () => {

// For now, we're using the user context to store the user, but letting react-query handle the loading
// In the future, we should remove the user context and use react-query to access the user
const userQuery = useQuery({
const { isLoading } = useQuery({
queryKey: noPersistence(["current-user"]),
queryFn: async () => {
const user = await getGitpodService().server.getLoggedInUser();
Expand All @@ -40,18 +40,13 @@ export const useUserLoader = () => {
retryDelay: (attemptIndex) => Math.min(1000 * 2 ** attemptIndex, 10000),
cacheTime: 1000 * 60 * 60 * 1, // 1 hour
staleTime: 1000 * 60 * 60 * 1, // 1 hour

onSuccess: (loadedUser) => {
setUser(loadedUser);
},
onSettled: (loadedUser) => {
trackLocation(!!loadedUser);
},
});

// onSuccess is deprecated: https://tkdodo.eu/blog/breaking-react-querys-api-on-purpose
useEffect(() => {
if (userQuery.data) {
setUser(userQuery.data);
}
}, [userQuery.data, setUser]);

return { user, loading: userQuery.isLoading };
return { user, loading: isLoading };
};