zapishis-client/apps/web/components/auth/update-profile.tsx
vchikalkin 54f69f7c36 Refactor UpdateProfile component to use useClientOnce for initial profile update
- Replaced useEffect with useClientOnce to handle the first login profile update more efficiently.
- Removed local state management for hasUpdated, simplifying the component logic.
- Updated localStorage handling to ensure the profile update occurs only on the first login.
2025-10-01 16:52:23 +03:00

28 lines
701 B
TypeScript

'use client';
import { useCustomerMutation } from '@/hooks/api/customers';
import { useClientOnce } from '@/hooks/telegram';
import { initData, useSignal } from '@telegram-apps/sdk-react';
export function UpdateProfile() {
const initDataUser = useSignal(initData.user);
const { mutate: updateProfile } = useCustomerMutation();
useClientOnce(() => {
if (
localStorage.getItem('firstLogin') === null ||
localStorage.getItem('firstLogin') === 'true'
) {
updateProfile({
data: {
active: true,
photoUrl: initDataUser?.photoUrl || undefined,
},
});
localStorage.setItem('firstLogin', 'false');
}
});
return null;
}