<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Delete Account</title>
<link rel="stylesheet" href="styles.css" />
<script src="https://unpkg.com/@supabase/supabase-js@2"></script>
</head>
<body>
<div class="container">
<h2>Delete Your Account</h2>
<label for="username">Email:</label>
<input id="username" type="text" placeholder="Enter your email" />
<label for="password">Password:</label>
<input id="password" type="password" placeholder="Enter your password" />
<button class="delete-btn" onclick="showConfirm()">Delete My Account</button>
</div>
<div id="confirmModal" class="modal">
<div class="modal-content">
<h3>Are you sure?</h3>
<p>This action <strong>cannot be undone</strong>. Your account will be permanently deleted.</p>
<div class="modal-buttons">
<button class="cancel-btn" onclick="hideConfirm()">Cancel</button>
<button class="confirm-btn" onclick="deleteAccount()">Yes, Delete</button>
</div>
</div>
</div>
<script>
function showConfirm() {
const username = document.getElementById('username').value.trim();
const password = document.getElementById('password').value.trim();
if (!username || !password) {
alert('Please enter your username and password.');
return;
}
document.getElementById('confirmModal').style.display = 'flex';
}
function hideConfirm() {
document.getElementById('confirmModal').style.display = 'none';
}
async function deleteAccount() {
const supabaseUrl = 'https://tgqtxgacnmcjejyrjcfg.supabase.co'
const supaAnon = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6InRncXR4Z2Fjbm1jamVqeXJqY2ZnIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NDY3MzM3OTQsImV4cCI6MjA2MjMwOTc5NH0.t4Elm2dukgy9bK4cHSKiy7K46DqGPMQ7B89NCxc06eo'
const client = supabase.createClient(supabaseUrl, supaAnon);
const email = document.getElementById('username').value
const password = document.getElementById('password').value
const {data, error} = await client.auth.signInWithPassword({email, password})
if(error){
alert('Login failed: '+error.message)
}else{
let access_token= data.session.access_token
const response = await fetch('https://server.sherlock.noahvanfleet.com/api/user', {
method:'DELETE',
headers:{
'Authorization': `Bearer ${access_token}`,
'Content-Type': 'applications/json'
}
})
const result = await response.json()
hideConfirm();
if(response.ok){
alert('Your account has been deleted.');
}else{
alert('Failed to delete account '+result.error)
}
}
}
</script>
</body>
</html>