commit
daa4702904
|
@ -102,13 +102,13 @@ const LoginPage = () => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const syncSessionWithBackend = async (authData: AuthResponse) => {
|
const syncSessionWithBackend = async (authData: AuthResponse) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch('http://localhost:2058/host-api/v1/users/session/', {
|
const response = await fetch('http://localhost:2058/host-api/v1/users/session/', {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
credentials: 'include', // Crucial for cookies
|
||||||
headers: { 'Content-Type': 'application/json' },
|
headers: { 'Content-Type': 'application/json' },
|
||||||
body: JSON.stringify({
|
body: JSON.stringify({
|
||||||
query: 'new',
|
|
||||||
accessToken: authData.token,
|
accessToken: authData.token,
|
||||||
email: authData.record.email,
|
email: authData.record.email,
|
||||||
name: authData.record.name,
|
name: authData.record.name,
|
||||||
|
@ -120,16 +120,14 @@ const LoginPage = () => {
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!response.ok) {
|
if (!response.ok) throw new Error('Failed to sync session');
|
||||||
throw new Error('Failed to sync session');
|
|
||||||
}
|
|
||||||
|
|
||||||
const data = await response.json();
|
const data = await response.json();
|
||||||
console.log('Session synced with backend:', data);
|
console.log('Session synced:', data);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error syncing session:', error);
|
console.error('Error syncing session:', error);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex items-center justify-center p-4">
|
<div className="min-h-screen flex items-center justify-center p-4">
|
||||||
|
|
|
@ -24,34 +24,29 @@ export default function ProfilePage() {
|
||||||
const [error, setError] = useState<string | null>(null);
|
const [error, setError] = useState<string | null>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const fetchData = async () => {
|
const fetchSessionData = async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
'http://localhost:2058/host-api/v1/users/get-profile-data/',
|
'http://localhost:2058/host-api/v1/users/get-profile-data/',
|
||||||
{
|
{
|
||||||
credentials: 'include',
|
credentials: 'include', // Crucial for cookies
|
||||||
headers: {
|
headers: { 'Accept': 'application/json' }
|
||||||
'Accept': 'application/json',
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
if (!response.ok) {
|
|
||||||
throw new Error(`HTTP error! status: ${response.status}`);
|
|
||||||
}
|
|
||||||
const data: UserData = await response.json();
|
|
||||||
// console.log('success message', data.success);
|
|
||||||
if(data.success === true){
|
|
||||||
setUserData(data);
|
|
||||||
// console.log('User Data', data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
if (!response.ok || !data.success) {
|
||||||
|
throw new Error(data.error || 'Session fetch failed');
|
||||||
|
}
|
||||||
|
setUserData(data);
|
||||||
|
return data.session_data;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Fetch error:', error);
|
console.error('Fetch error:', error);
|
||||||
setError(error instanceof Error ? error.message : 'An unknown error occurred');
|
throw error;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
fetchData();
|
fetchSessionData();
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
if (error) {
|
if (error) {
|
||||||
|
|
Loading…
Reference in New Issue