feat: Implement person management features
- Added hooks for listing, creating, updating, deleting, sharing, and merging people. - Introduced a new route for person details and media. - Implemented clustering faces functionality. - Created services for person-related API interactions. feat: Introduce tag management functionality - Added hooks for listing, adding, and removing tags from media. - Created services for tag-related API interactions. feat: Enhance user authentication handling - Added a hook to fetch current user details. - Updated auth storage to manage user state more effectively. feat: Update album management features - Enhanced album service to return created album details. - Updated API handlers to return album responses upon creation. - Modified album repository to return created album. feat: Implement media management improvements - Added media details fetching and processing of media URLs. - Enhanced media upload functionality to return processed media. feat: Introduce face management features - Added services for listing faces for media and assigning faces to persons. fix: Update API client to clear authentication state on 401 errors.
This commit is contained in:
@@ -1,37 +1,58 @@
|
||||
import type { User } from "@/domain/types"
|
||||
import { useAuthStorage } from "@/hooks/use-auth-storage"
|
||||
import apiClient from "@/services/api-client"
|
||||
import { useNavigate } from "@tanstack/react-router"
|
||||
import { useMutation } from "@tanstack/react-query"
|
||||
import { useAuthStorage } from "@/hooks/use-auth-storage";
|
||||
import { useNavigate } from "@tanstack/react-router";
|
||||
import { useMutation } from "@tanstack/react-query";
|
||||
import { login, register } from "@/services/auth-service";
|
||||
|
||||
type LoginCredentials = {
|
||||
usernameOrEmail: string
|
||||
password: string
|
||||
}
|
||||
// Types
|
||||
export type LoginCredentials = {
|
||||
usernameOrEmail: string;
|
||||
password: string;
|
||||
};
|
||||
|
||||
type LoginResponse = {
|
||||
token: string
|
||||
user: User
|
||||
}
|
||||
export type LoginResponse = {
|
||||
token: string;
|
||||
};
|
||||
|
||||
const login = async (credentials: LoginCredentials): Promise<LoginResponse> => {
|
||||
const { data } = await apiClient.post('/auth/login', credentials)
|
||||
return data
|
||||
}
|
||||
export type RegisterPayload = LoginCredentials & {
|
||||
email: string;
|
||||
};
|
||||
|
||||
/**
|
||||
* Mutation hook for user login.
|
||||
*/
|
||||
export const useLogin = () => {
|
||||
const navigate = useNavigate()
|
||||
const { setToken } = useAuthStorage()
|
||||
const navigate = useNavigate();
|
||||
const { setToken } = useAuthStorage();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: login,
|
||||
onSuccess: (data) => {
|
||||
setToken(data.token, data.user)
|
||||
navigate({ to: '/' })
|
||||
setToken(data.token);
|
||||
navigate({ to: "/" });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error('Login failed:', error)
|
||||
console.error("Login failed:", error);
|
||||
// TODO: Add user-facing error toast
|
||||
},
|
||||
})
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Mutation hook for user registration.
|
||||
*/
|
||||
export const useRegister = () => {
|
||||
const navigate = useNavigate();
|
||||
|
||||
return useMutation({
|
||||
mutationFn: register,
|
||||
onSuccess: () => {
|
||||
// After successful registration, send them to the login page
|
||||
// TODO: Add a success toast: "Registration successful! Please log in."
|
||||
navigate({ to: "/login" });
|
||||
},
|
||||
onError: (error) => {
|
||||
console.error("Registration failed:", error);
|
||||
// TODO: Add user-facing error toast
|
||||
},
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user