diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 16828d7..12659d5 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -102,34 +102,32 @@ const LoginPage = () => { } }; - const syncSessionWithBackend = async (authData: AuthResponse) => { - try { - const response = await fetch('http://localhost:2058/host-api/v1/users/session/', { - method: 'POST', - headers: { 'Content-Type': 'application/json' }, - body: JSON.stringify({ - query: 'new', - accessToken: authData.token, - email: authData.record.email, - name: authData.record.name, - avatar: authData.record.avatar - ? pb.files.getUrl(authData.record, authData.record.avatar) - : '', - isAuthenticated: true, - id: authData.record.id - }) - }); - - if (!response.ok) { - throw new Error('Failed to sync session'); - } - - const data = await response.json(); - console.log('Session synced with backend:', data); - } catch (error) { - console.error('Error syncing session:', error); - } - }; +const syncSessionWithBackend = async (authData: AuthResponse) => { + try { + const response = await fetch('http://localhost:2058/host-api/v1/users/session/', { + method: 'POST', + credentials: 'include', // Crucial for cookies + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ + accessToken: authData.token, + email: authData.record.email, + name: authData.record.name, + avatar: authData.record.avatar + ? pb.files.getUrl(authData.record, authData.record.avatar) + : '', + isAuthenticated: true, + id: authData.record.id + }) + }); + + if (!response.ok) throw new Error('Failed to sync session'); + + const data = await response.json(); + console.log('Session synced:', data); + } catch (error) { + console.error('Error syncing session:', error); + } +}; return (