mirror of
https://github.com/jakejarvis/sofa.git
synced 2026-10-16 01:05:42 -04:00
fix(web): clear cached user data on sign-out and sign-in
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
4 files changed
+30
-2
No files matched your search
@@ -9,6 +9,7 @@ import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { useResetUserState } from "@/hooks/use-reset-user-state";
|
||||
import { authClient, signIn, signUp } from "@/lib/auth/client";
|
||||
import { useAppForm } from "@/lib/form";
|
||||
|
||||
@@ -40,6 +41,7 @@ export function AuthForm({
|
||||
}) {
|
||||
const { t } = useLingui();
|
||||
const navigate = useNavigate();
|
||||
const resetUserState = useResetUserState();
|
||||
const [error, setError] = useState("");
|
||||
const [oidcLoading, setOidcLoading] = useState(false);
|
||||
|
||||
@@ -70,6 +72,7 @@ export function AuthForm({
|
||||
return;
|
||||
}
|
||||
}
|
||||
resetUserState();
|
||||
void navigate({ to: isRegister ? "/onboarding" : "/dashboard" });
|
||||
} catch {
|
||||
setError(t`Something went wrong`);
|
||||
|
||||
@@ -25,6 +25,7 @@ import {
|
||||
} from "@/components/ui/dropdown-menu";
|
||||
import { Kbd } from "@/components/ui/kbd";
|
||||
import { Separator } from "@/components/ui/separator";
|
||||
import { useResetUserState } from "@/hooks/use-reset-user-state";
|
||||
import { commandPaletteOpenAtom } from "@/lib/atoms/command-palette";
|
||||
import { signOut } from "@/lib/auth/client";
|
||||
|
||||
@@ -115,6 +116,7 @@ export function NavBar({
|
||||
}) {
|
||||
const { t } = useLingui();
|
||||
const navigate = useNavigate();
|
||||
const resetUserState = useResetUserState();
|
||||
const { pathname } = useLocation();
|
||||
const setCommandPaletteOpen = useSetAtom(commandPaletteOpenAtom);
|
||||
|
||||
@@ -249,7 +251,8 @@ export function NavBar({
|
||||
variant="destructive"
|
||||
onSelect={async () => {
|
||||
await signOut();
|
||||
void navigate({ to: "/" });
|
||||
await navigate({ to: "/" });
|
||||
resetUserState();
|
||||
}}
|
||||
className="cursor-pointer text-[13px]"
|
||||
>
|
||||
|
||||
@@ -39,6 +39,7 @@ import { Label } from "@/components/ui/label";
|
||||
import { Progress } from "@/components/ui/progress";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
||||
import { useResetUserState } from "@/hooks/use-reset-user-state";
|
||||
import { authClient, signOut } from "@/lib/auth/client";
|
||||
import { getErrorMessage } from "@/lib/error-messages";
|
||||
import { useAppForm } from "@/lib/form";
|
||||
@@ -59,6 +60,7 @@ export function AccountSection({
|
||||
}) {
|
||||
const { t } = useLingui();
|
||||
const navigate = useNavigate();
|
||||
const resetUserState = useResetUserState();
|
||||
const router = useRouter();
|
||||
const [avatarUrl, setAvatarUrl] = useState(user.image);
|
||||
const [isHovered, setIsHovered] = useState(false);
|
||||
@@ -318,7 +320,8 @@ export function AccountSection({
|
||||
variant="destructive"
|
||||
onClick={async () => {
|
||||
await signOut();
|
||||
void navigate({ to: "/" });
|
||||
await navigate({ to: "/" });
|
||||
resetUserState();
|
||||
}}
|
||||
>
|
||||
<IconLogout aria-hidden={true} />
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
import { useQueryClient } from "@tanstack/react-query";
|
||||
import { useSetAtom } from "jotai";
|
||||
import { RESET } from "jotai/utils";
|
||||
import { useCallback } from "react";
|
||||
|
||||
import { recentSearchesAtom } from "@/lib/atoms/command-palette";
|
||||
|
||||
/**
|
||||
* Drop everything cached for the current user. Query keys are not scoped by
|
||||
* user, so this must run on sign-out and before entering the app after sign-in.
|
||||
*/
|
||||
export function useResetUserState() {
|
||||
const queryClient = useQueryClient();
|
||||
const setRecentSearches = useSetAtom(recentSearchesAtom);
|
||||
return useCallback(() => {
|
||||
queryClient.clear();
|
||||
setRecentSearches(RESET);
|
||||
}, [queryClient, setRecentSearches]);
|
||||
}
|
||||
Reference in new issue
Block a user