aktuazalizacja profilow,prefernecji,bezpiecznestwa
This commit is contained in:
+39
-3
@@ -9,7 +9,8 @@ export type PreferredLanguage = 'PL' | 'EN' | 'UK' | 'DE';
|
||||
|
||||
export type Currency = 'PLN' | 'EUR' | 'USD';
|
||||
export type AreaUnit = 'M2' | 'FT2';
|
||||
export type ProfileVisibility = 'PUBLIC' | 'CONTACTS' | 'PRIVATE';
|
||||
// Profil jest publiczny, dopoki wlasciciel sam nie ustawi go jako prywatny.
|
||||
export type ProfileVisibility = 'PUBLIC' | 'PRIVATE';
|
||||
|
||||
/**
|
||||
* Ustawienia konta trzymane na serwerze (/api/me/settings). Zgody marketingowe celowo tu nie leza -
|
||||
@@ -41,6 +42,20 @@ export type UserSettings = {
|
||||
// Zapis czesciowy: pominiete pole zostaje bez zmian, pusty tekst je czysci, liczba ujemna zeruje.
|
||||
export type UserSettingsPatch = Partial<Record<keyof UserSettings, unknown>>;
|
||||
|
||||
/**
|
||||
* Preferencje wyszukiwania w lekkiej postaci (/api/me/settings/search) - wyszukiwarka pobiera je
|
||||
* przy wejsciu do aplikacji, wiec nie ciagniemy przy okazji zdjec z pelnych ustawien.
|
||||
*/
|
||||
export type SearchPreferences = {
|
||||
locations: string | null;
|
||||
propertyType: string | null;
|
||||
budgetMax: number | null;
|
||||
areaMin: number | null;
|
||||
areaMax: number | null;
|
||||
roomsMin: number | null;
|
||||
roomsMax: number | null;
|
||||
};
|
||||
|
||||
export type AuthUser = {
|
||||
id: number;
|
||||
email: string;
|
||||
@@ -60,6 +75,8 @@ export type AuthUser = {
|
||||
blocked: boolean;
|
||||
promotionCredits: number;
|
||||
createdAt: string;
|
||||
// Zdjecie profilowe z ustawien konta - null, gdy uzytkownik zadnego nie ustawil.
|
||||
avatarImage: string | null;
|
||||
};
|
||||
|
||||
type AuthResponse = { token: string; user: AuthUser };
|
||||
@@ -89,8 +106,11 @@ type AuthContextValue = {
|
||||
resendPhoneOtp: (email: string) => Promise<void>;
|
||||
updateProfile: (profile: ProfileUpdate) => Promise<AuthUser>;
|
||||
changePassword: (currentPassword: string, newPassword: string) => Promise<void>;
|
||||
verifyPassword: (password: string) => Promise<void>;
|
||||
passwordCooldown: () => Promise<number>;
|
||||
deleteAccount: (password: string) => Promise<void>;
|
||||
loadSettings: () => Promise<UserSettings>;
|
||||
loadSearchPreferences: () => Promise<SearchPreferences>;
|
||||
saveSettings: (patch: UserSettingsPatch) => Promise<UserSettings>;
|
||||
refreshUser: () => Promise<AuthUser | null>;
|
||||
logout: () => void;
|
||||
@@ -286,6 +306,20 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Sprawdzenie dotychczasowego hasla bez zmiany czegokolwiek. Rzuca bledem, gdy haslo jest zle.
|
||||
const verifyPassword = useCallback(async (password: string) => {
|
||||
await apiFetch<void>('/auth/verify-password', {
|
||||
method: 'POST',
|
||||
body: JSON.stringify({ password }),
|
||||
});
|
||||
}, []);
|
||||
|
||||
// Ile sekund zostalo do momentu, w ktorym serwer przyjmie kolejna zmiane hasla.
|
||||
const passwordCooldown = useCallback(async () => {
|
||||
const data = await apiFetch<{ secondsLeft: number }>('/auth/password-cooldown');
|
||||
return data.secondsLeft;
|
||||
}, []);
|
||||
|
||||
// Po usunieciu konta token jest bezuzyteczny - czyscimy sesje od razu, bez czekania na 401.
|
||||
const deleteAccount = useCallback(async (password: string) => {
|
||||
await apiFetch<void>('/auth/me', {
|
||||
@@ -299,6 +333,8 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
|
||||
const loadSettings = useCallback(async () => apiFetch<UserSettings>('/me/settings'), []);
|
||||
|
||||
const loadSearchPreferences = useCallback(async () => apiFetch<SearchPreferences>('/me/settings/search'), []);
|
||||
|
||||
const saveSettings = useCallback(
|
||||
async (patch: UserSettingsPatch) =>
|
||||
apiFetch<UserSettings>('/me/settings', { method: 'PUT', body: JSON.stringify(patch) }),
|
||||
@@ -329,11 +365,11 @@ export function AuthProvider({ children }: { children: ReactNode }) {
|
||||
() => ({
|
||||
user, token, loading, login, register, socialLogin,
|
||||
activateAccount, resendActivation, forgotPassword, resetPassword, verifyPhone, resendPhoneOtp,
|
||||
updateProfile, changePassword, deleteAccount, loadSettings, saveSettings, refreshUser, logout,
|
||||
updateProfile, changePassword, verifyPassword, passwordCooldown, deleteAccount, loadSettings, loadSearchPreferences, saveSettings, refreshUser, logout,
|
||||
}),
|
||||
[user, token, loading, login, register, socialLogin,
|
||||
activateAccount, resendActivation, forgotPassword, resetPassword, verifyPhone, resendPhoneOtp,
|
||||
updateProfile, changePassword, deleteAccount, loadSettings, saveSettings, refreshUser, logout],
|
||||
updateProfile, changePassword, verifyPassword, passwordCooldown, deleteAccount, loadSettings, loadSearchPreferences, saveSettings, refreshUser, logout],
|
||||
);
|
||||
|
||||
return <AuthContext.Provider value={value}>{children}</AuthContext.Provider>;
|
||||
|
||||
Reference in New Issue
Block a user