Cài đặt thành công tính năng người dùng đăng nhập

This commit is contained in:
2026-06-13 17:57:00 +07:00
parent f38d7e01a1
commit ea5799ffb5
15 changed files with 176 additions and 21 deletions
+13
View File
@@ -8,11 +8,18 @@ const App = () => {
type View = 'landing' | 'explore' | 'detail' | 'signup';
const [view, setView] = useState<View>('landing');
const [isInitialSetup, setIsInitialSetup] = useState(false);
const [user, setUser] = useState<any>(null);
useEffect(() => {
// Tự động xác định địa chỉ IP của Backend dựa trên hostname hiện tại
const API_BASE = `http://${window.location.hostname}:3001`;
// Khôi phục phiên đăng nhập từ localStorage
const savedUser = localStorage.getItem('user');
if (savedUser) {
setUser(JSON.parse(savedUser));
}
// Kiểm tra xem hệ thống đã được cài đặt chưa
fetch(`${API_BASE}/api/v1/auth/status`)
.then(res => res.ok ? res.json() : Promise.reject())
@@ -20,6 +27,11 @@ const App = () => {
.catch(() => setIsInitialSetup(false));
}, [view]);
const handleLoginSuccess = (userData: any) => {
setUser(userData);
setView('explore'); // Chuyển sang bản đồ khám phá sau khi đăng nhập
};
return (
<div className="app-container">
{view === 'landing' && (
@@ -28,6 +40,7 @@ const App = () => {
onContinue={() => setView('explore')}
onGoToSignup={() => setView('signup')}
onGoToMap={() => setView('explore')}
onLoginSuccess={handleLoginSuccess}
/>
)}