Fixes login redirection
This commit is contained in:
@@ -3,6 +3,7 @@ import { useQuery, useMutation, useQueryClient } from "@tanstack/react-query";
|
|||||||
import type { ReactNode } from "react";
|
import type { ReactNode } from "react";
|
||||||
import { pb } from "@/lib/pocketbase";
|
import { pb } from "@/lib/pocketbase";
|
||||||
import type { AuthRecord } from "pocketbase";
|
import type { AuthRecord } from "pocketbase";
|
||||||
|
import { useNavigate } from "@tanstack/react-router";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Represents the shape of the authenticated user object from PocketBase.
|
* Represents the shape of the authenticated user object from PocketBase.
|
||||||
@@ -43,6 +44,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
queryKey: ["auth", "user"],
|
queryKey: ["auth", "user"],
|
||||||
queryFn: fetchUser,
|
queryFn: fetchUser,
|
||||||
});
|
});
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const loginMutation = useMutation({
|
const loginMutation = useMutation({
|
||||||
mutationFn: async ({
|
mutationFn: async ({
|
||||||
@@ -92,6 +94,7 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const login = useCallback(
|
const login = useCallback(
|
||||||
async (email: string, password: string) => {
|
async (email: string, password: string) => {
|
||||||
await loginMutation.mutateAsync({ email, password });
|
await loginMutation.mutateAsync({ email, password });
|
||||||
|
navigate({ to: "/campaigns" });
|
||||||
},
|
},
|
||||||
[loginMutation],
|
[loginMutation],
|
||||||
);
|
);
|
||||||
@@ -99,12 +102,14 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
|||||||
const signup = useCallback(
|
const signup = useCallback(
|
||||||
async (email: string, password: string, passwordConfirm: string) => {
|
async (email: string, password: string, passwordConfirm: string) => {
|
||||||
await signupMutation.mutateAsync({ email, password, passwordConfirm });
|
await signupMutation.mutateAsync({ email, password, passwordConfirm });
|
||||||
|
navigate({ to: "/campaigns" });
|
||||||
},
|
},
|
||||||
[signupMutation],
|
[signupMutation],
|
||||||
);
|
);
|
||||||
|
|
||||||
const logout = useCallback(async () => {
|
const logout = useCallback(async () => {
|
||||||
await logoutMutation.mutateAsync();
|
await logoutMutation.mutateAsync();
|
||||||
|
navigate({ to: "/" });
|
||||||
}, [logoutMutation]);
|
}, [logoutMutation]);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
|||||||
Reference in New Issue
Block a user