x
This commit is contained in:
parent
64eeccde0e
commit
932c310b60
1 changed files with 40 additions and 20 deletions
60
index.html
60
index.html
|
|
@ -534,28 +534,48 @@
|
||||||
createUser(currentUser);
|
createUser(currentUser);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create user in database
|
// Update the createUser function in your frontend JavaScript
|
||||||
async function createUser(user) {
|
async function createUser(user) {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`${API_BASE_URL}/users`, {
|
console.log("Creating user:", user); // Log the user data
|
||||||
method: 'POST',
|
|
||||||
headers: {
|
const response = await fetch(`${API_BASE_URL}/users`, {
|
||||||
'Content-Type': 'application/json'
|
method: 'POST',
|
||||||
},
|
headers: {
|
||||||
body: JSON.stringify({
|
'Content-Type': 'application/json'
|
||||||
id: user.id,
|
},
|
||||||
name: user.name
|
body: JSON.stringify({
|
||||||
})
|
id: user.id,
|
||||||
});
|
name: user.name
|
||||||
|
})
|
||||||
if (!response.ok) {
|
});
|
||||||
throw new Error('Failed to create user');
|
|
||||||
}
|
if (!response.ok) {
|
||||||
} catch (error) {
|
const errorData = await response.json();
|
||||||
console.error('Error creating user:', error);
|
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
|
// Catchy political slogans for placeholder text
|
||||||
const placeholders = [
|
const placeholders = [
|
||||||
"Your idea to revolutionize Australia? (280 character limit)",
|
"Your idea to revolutionize Australia? (280 character limit)",
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue