parts of function after supabase data retrieval/upload not working until button is pressed a second time

Viewed 184

I am trying to make an electron app and have it upload to a supabase database from an HTML form. The HTML part works just fine, and running the correct function in a separate file works just fine as well, but its until I try to either retrieve data or upload data to the database that it doesnt work until the submit button on the HTML form is pressed for the second time. But yet, whenever I try to upload data, it again only works on the second click, but acts as if it is happening twice.

Here is the HTML code for the button and its function:

<input type='button' class='submit' id='submit' onClick="send()">
(...)
<script>
const user = require('../utils/supabase/user.js')

const { createClient } = require('@supabase/supabase-js')

const supabase = createClient(
'*********************',
'*********************')

    

    async function send(){
        

        var email = 'test@test.com'
        var discord = 'test'
        var username = 'test-email'
        var password = 'test'

        
            const result1 = await user.newUser(supabase, email, discord, username, password)
                console.log('------')
                console.log(result1)
            
            
            
        

        var result = await user.loadUser(supabase, username)
        console.log('result recieved')
        console.log(result)

        
    }

</script>

User.js:

var presses = 0

async function loadUser(supabase, username){
presses++
console.log(presses) //testing if it registers all clicks or just the second click

let result = await supabase
    .from('test')
    .select('test1, test2')
    .eq('test1',username)

return result.data
}

async function newUser(supabase, email, discord, username, password){
console.log('user being added')
let result = await supabase
    .from('test')
    .insert([
        {test1: username, test2: password}
    ]).then((returns) => {
        
        console.log('returns = ')
        console.log(returns)
    })
    .catch(console.error())
    
    // console.log(result.data)
}

module.exports = {loadUser, newUser, presses}

on the first click of the submit button, all that is logged is "user being added" then on the second click, that same message is logged again, but then I get this as well: its acting as if it was pressed twice, but doesnt act until it get pressed for the second time

0 Answers
Related