I am trying to delete a row from the database and when I load the page, the file throws an error saying SyntaxError: Unexpected identifier 'supabase'. Expected ';' after variable declaration.
Following is my function code:
window.deleteChap = async function deleteChap(x) {
let chapid = chapids[x];
Swal.fire({
title: `Are you sure you want to delete the chapter? This action is irreversible.`,
showCancelButton: true,
confirmButtonText: 'Yes, delete it!',
}).then((result) => {
if (result.isConfirmed) {
const { data, error } = await supabase.from('chapters').eq('id', chapid).delete();
if (error) {
erroralert(error.message);
} else {
successalert(`Chapter deleted successfully.`);
}
}
})
}
The supabase client has already been initialised this way:
let supabase;
$.ajax({
url: "/keys",
success: async function( result ) {
result = JSON.parse(result);
supabase = createClient(result.link, result.anon_key);
}});
The javascript file is linked to the html with <script defer src="/js/dnovelinfo.js" type="module"></script>
I am not sure why the error is being thrown, even when I haven't interacted with the page (the page was only reloaded to see latest changes)