-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathicon-change.js
More file actions
53 lines (43 loc) · 1.91 KB
/
icon-change.js
File metadata and controls
53 lines (43 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// Initialize Supabase client at the very top
const supabaseUrl = "https://fossoibkacvvhitsnfhv.supabase.co"; // Replace with your Supabase URL
const supabaseKey = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6ImZvc3NvaWJrYWN2dmhpdHNuZmh2Iiwicm9sZSI6ImFub24iLCJpYXQiOjE3MzM1OTMxODEsImV4cCI6MjA0OTE2OTE4MX0.UgiksbLKT8bNsD_fvMldt08ObaW0-chSHWBJbqNqS4E";
window.supabase = supabase.createClient(supabaseUrl, supabaseKey);
// Debug to confirm initialization
console.log('Supabase client initialized:', supabase);
// Now your code can safely use 'supabase'
document.addEventListener("DOMContentLoaded", async () => {
const loginButton = document.getElementById("login-btn");
const profileButton = document.getElementById("profile-btn");
// Check for an active session
const { data: session, error } = await supabase.auth.getSession();
if (error) {
console.error("Error fetching session:", error.message);
}
if (session && session.session) {
console.log("Session exists:", session.session);
loginButton.style.display = "none";
profileButton.style.display = "block";
} else {
console.log("No session found.");
loginButton.style.display = "block";
profileButton.style.display = "none";
}
});
// Example logout function
async function logout() {
await supabase.auth.signOut();
alert("Logged out successfully!");
window.location.reload();
}
// Listen for auth state changes (optional for dynamic updates)
supabase.auth.onAuthStateChange((event, session) => {
const loginButton = document.getElementById("login-btn");
const profileContainer = document.getElementById("profile-dropdown");
if (session) {
loginButton.style.display = "none";
profileContainer.style.display = "inline-block";
} else {
loginButton.style.display = "block";
profileContainer.style.display = "none";
}
});