From 9f1e38ce472f798973a2aedc8a3aacd305fd6087 Mon Sep 17 00:00:00 2001 From: Drew Haven Date: Fri, 13 Jun 2025 11:21:23 -0700 Subject: [PATCH] Fixes login redirection --- src/context/auth/AuthContext.tsx | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/context/auth/AuthContext.tsx b/src/context/auth/AuthContext.tsx index b7a76b5..e903d97 100644 --- a/src/context/auth/AuthContext.tsx +++ b/src/context/auth/AuthContext.tsx @@ -3,6 +3,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query"; import type { ReactNode } from "react"; import { pb } from "@/lib/pocketbase"; import type { AuthRecord } from "pocketbase"; +import { useNavigate } from "@tanstack/react-router"; /** * Represents the shape of the authenticated user object from PocketBase. @@ -43,6 +44,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { queryKey: ["auth", "user"], queryFn: fetchUser, }); + const navigate = useNavigate(); const loginMutation = useMutation({ mutationFn: async ({ @@ -92,6 +94,7 @@ export function AuthProvider({ children }: { children: ReactNode }) { const login = useCallback( async (email: string, password: string) => { await loginMutation.mutateAsync({ email, password }); + navigate({ to: "/campaigns" }); }, [loginMutation], ); @@ -99,12 +102,14 @@ export function AuthProvider({ children }: { children: ReactNode }) { const signup = useCallback( async (email: string, password: string, passwordConfirm: string) => { await signupMutation.mutateAsync({ email, password, passwordConfirm }); + navigate({ to: "/campaigns" }); }, [signupMutation], ); const logout = useCallback(async () => { await logoutMutation.mutateAsync(); + navigate({ to: "/" }); }, [logoutMutation]); return (