feat(auth): implement login authorization

feat(font): implement satoshi font family
This commit is contained in:
shafin-r
2026-01-11 15:44:51 +06:00
parent bd6f1d2333
commit 1506c25796
35 changed files with 3870 additions and 7 deletions

75
src/stores/authStore.ts Normal file
View File

@ -0,0 +1,75 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { api, type User, type LoginRequest } from "../utils/api";
interface AuthState {
user: User | null;
token: string | null;
isAuthenticated: boolean;
isLoading: boolean;
error: string | null;
login: (credentials: LoginRequest) => Promise<boolean>;
logout: () => void;
clearError: () => void;
}
export const useAuthStore = create<AuthState>()(
persist(
(set) => ({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
error: null,
login: async (credentials: LoginRequest) => {
set({ isLoading: true, error: null });
try {
const response = await api.login(credentials);
set({
user: response.user,
token: response.token,
isAuthenticated: true,
isLoading: false,
error: null,
});
return true;
} catch (error) {
const errorMessage =
error instanceof Error ? error.message : "Login failed";
set({
user: null,
token: null,
isAuthenticated: false,
isLoading: false,
error: errorMessage,
});
return false;
}
},
logout: () => {
set({
user: null,
token: null,
isAuthenticated: false,
error: null,
});
},
clearError: () => set({ error: null }),
}),
{
name: "auth-storage",
partialize: (state) => ({
user: state.user,
token: state.token,
isAuthenticated: state.isAuthenticated,
}),
}
)
);