From 932c310b60aedda0ff5c98327f6faf6d823e1b56 Mon Sep 17 00:00:00 2001 From: Omar Najjar Date: Sat, 8 Mar 2025 01:43:13 +1100 Subject: [PATCH] x --- index.html | 60 ++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 40 insertions(+), 20 deletions(-) diff --git a/index.html b/index.html index fa6fbd9..b369cec 100644 --- a/index.html +++ b/index.html @@ -534,28 +534,48 @@ createUser(currentUser); } - // Create user in database - async function createUser(user) { - try { - const response = await fetch(`${API_BASE_URL}/users`, { - method: 'POST', - headers: { - 'Content-Type': 'application/json' - }, - body: JSON.stringify({ - id: user.id, - name: user.name - }) - }); - - if (!response.ok) { - throw new Error('Failed to create user'); - } - } catch (error) { - console.error('Error creating user:', error); - } + // Update the createUser function in your frontend JavaScript +async function createUser(user) { + try { + console.log("Creating user:", user); // Log the user data + + const response = await fetch(`${API_BASE_URL}/users`, { + method: 'POST', + headers: { + 'Content-Type': 'application/json' + }, + body: JSON.stringify({ + id: user.id, + name: user.name + }) + }); + + if (!response.ok) { + const errorData = await response.json(); + console.error("User creation API error:", errorData); + throw new Error('Failed to create user'); } + const data = await response.json(); + console.log("User creation successful:", data); + return data; + } catch (error) { + console.error('Error creating user:', error); + throw error; + } +} + +// Ensure user is created before posting proposals +window.addEventListener('DOMContentLoaded', async () => { + // Try to create the user immediately when page loads + try { + await createUser(currentUser); + console.log("User registration complete"); + } catch (error) { + console.error("Failed to register user on page load"); + } +}); + // Catchy political slogans for placeholder text const placeholders = [ "Your idea to revolutionize Australia? (280 character limit)",