Compare commits
3 Commits
38eee14253
...
9f1e38ce47
| Author | SHA1 | Date | |
|---|---|---|---|
| 9f1e38ce47 | |||
| c28073d516 | |||
| 6845bd06bf |
@@ -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 (
|
||||
|
||||
Reference in New Issue
Block a user