|
40 | 40 | <nav id="navbar" class="fixed top-0 left-0 w-full bg-gray-900/90 backdrop-blur-lg border-b border-white/10 z-50"> |
41 | 41 | <div class="max-w-5xl mx-auto px-6 h-14 flex items-center justify-end"> |
42 | 42 |
|
| 43 | + <!-- LOGIN BUTTON --> |
| 44 | + <button onclick="signInWithGoogle()" |
| 45 | + id="login-btn" |
| 46 | + class="px-4 py-2 bg-brand text-black font-semibold rounded-lg hover:bg-brand/80 transition mr-3"> |
| 47 | + Login |
| 48 | + </button> |
| 49 | + |
43 | 50 | <!-- User info container --> |
44 | 51 | <div id="user-nav" class="hidden items-center gap-3 text-sm"> |
45 | 52 |
|
@@ -206,25 +213,44 @@ <h3 class="text-xl font-semibold mb-4 text-brand">High-precision 3D printing</h3 |
206 | 213 | <script> |
207 | 214 | const SUPABASE_URL = "https://ixrcmespfkbvubxsaqvf.supabase.co"; |
208 | 215 | const SUPABASE_ANON_KEY = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZSIsInJlZiI6Iml4cmNtZXNwZmtidnVieHNhcXZmIiwicm9sZSI6ImFub24iLCJpYXQiOjE3NjM1ODc3MDgsImV4cCI6MjA3OTE2MzcwOH0.OONsZEtb-VUAsBgTICYixl8M-GU4dMT6FK-Gg3s3i94"; |
| 216 | + |
209 | 217 | const supabase = supabase.createClient(SUPABASE_URL, SUPABASE_ANON_KEY); |
210 | 218 |
|
211 | 219 | async function logout() { |
212 | 220 | await supabase.auth.signOut(); |
213 | 221 | location.reload(); |
214 | 222 | } |
215 | 223 |
|
216 | | - // Load user on page load |
| 224 | + async function signInWithGoogle() { |
| 225 | + const { data, error } = await supabase.auth.signInWithOAuth({ |
| 226 | + provider: "google", |
| 227 | + options: { |
| 228 | + redirectTo: "https://coderserg.github.io/auth/callback.html" |
| 229 | + } |
| 230 | + }); |
| 231 | + |
| 232 | + if (error) console.error(error); |
| 233 | + if (data?.url) window.location.href = data.url; |
| 234 | + } |
| 235 | + |
| 236 | + // Load user on page load (ONE time) |
217 | 237 | document.addEventListener("DOMContentLoaded", async () => { |
218 | 238 | const { data } = await supabase.auth.getUser(); |
219 | 239 | const user = data.user; |
220 | 240 |
|
221 | 241 | const userNav = document.getElementById("user-nav"); |
222 | 242 | const userNameEl = document.getElementById("user-name"); |
| 243 | + const loginBtn = document.getElementById("login-btn"); |
223 | 244 |
|
224 | 245 | if (user) { |
225 | 246 | const name = user.user_metadata.full_name || user.email; |
| 247 | + |
| 248 | + // Show user info + logout |
226 | 249 | userNameEl.textContent = name; |
227 | 250 | userNav.classList.remove("hidden"); |
| 251 | + |
| 252 | + // Hide login button |
| 253 | + loginBtn.classList.add("hidden"); |
228 | 254 | } |
229 | 255 | }); |
230 | 256 | </script> |
|
0 commit comments