|
| 1 | +--- |
| 2 | +--- |
| 3 | + |
| 4 | +<!doctype html> |
| 5 | +<html lang="en"> |
| 6 | + <head> |
| 7 | + <meta charset="utf-8" /> |
| 8 | + <meta name="viewport" content="width=device-width" /> |
| 9 | + <meta name="robots" content="noindex, nofollow" /> |
| 10 | + <meta name="theme-color" content="#1C1C1C" /> |
| 11 | + <title>Organizer sign in | DevCongress</title> |
| 12 | + </head> |
| 13 | + <body> |
| 14 | + <main> |
| 15 | + <section class="card" aria-labelledby="title"> |
| 16 | + <img src="/images/logo.png" alt="dev:congress{};" height="42" /> |
| 17 | + <p class="eyebrow">Organizer access</p> |
| 18 | + <h1 id="title">Sign in with Google</h1> |
| 19 | + <p>Only approved DevCongress organizers can continue.</p> |
| 20 | + <p class="message" data-message role="status" aria-live="polite"></p> |
| 21 | + <button type="button" data-sign-in>Continue with Google</button> |
| 22 | + <button type="button" class="secondary" data-sign-out hidden>Sign out</button> |
| 23 | + </section> |
| 24 | + </main> |
| 25 | + </body> |
| 26 | +</html> |
| 27 | + |
| 28 | +<style> |
| 29 | + :root { color: #e5e5e5; background: #1c1c1c; font-family: Inter, ui-sans-serif, system-ui, sans-serif; } |
| 30 | + * { box-sizing: border-box; } |
| 31 | + body { margin: 0; min-width: 320px; } |
| 32 | + main { display: grid; min-height: 100vh; place-items: center; padding: 24px; } |
| 33 | + .card { width: min(100%, 460px); padding: 40px; border: 1px solid #3a3a3a; border-radius: 12px; background: #242424; } |
| 34 | + img { display: block; width: auto; margin-bottom: 36px; } |
| 35 | + .eyebrow { margin: 0 0 10px; color: #a1a1a1; font-size: 12px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; } |
| 36 | + h1 { margin: 0; letter-spacing: -0.15px; font-size: clamp(32px, 8vw, 44px); line-height: 1.05; } |
| 37 | + p:not(.eyebrow) { color: #a1a1a1; line-height: 1.6; } |
| 38 | + .message { min-height: 24px; color: #e5e5e5 !important; font-size: 14px; } |
| 39 | + button { width: 100%; min-height: 46px; border: 0; border-radius: 8px; background: #e5e5e5; color: #1c1c1c; font: inherit; font-weight: 700; cursor: pointer; } |
| 40 | + button:disabled { cursor: wait; opacity: .65; } |
| 41 | + button.secondary { margin-top: 12px; border: 1px solid #4a4a4a; background: transparent; color: #e5e5e5; } |
| 42 | +</style> |
| 43 | + |
| 44 | +<script> |
| 45 | + import { createClient } from '@supabase/supabase-js'; |
| 46 | + |
| 47 | + type AuthConfig = { supabaseUrl: string; supabaseAnonKey: string }; |
| 48 | + const message = document.querySelector<HTMLElement>('[data-message]'); |
| 49 | + const signIn = document.querySelector<HTMLButtonElement>('[data-sign-in]'); |
| 50 | + const signOut = document.querySelector<HTMLButtonElement>('[data-sign-out]'); |
| 51 | + |
| 52 | + function setMessage(value: string) { if (message) message.textContent = value; } |
| 53 | + |
| 54 | + async function authConfig(): Promise<AuthConfig> { |
| 55 | + const response = await fetch('/api/auth/config', { credentials: 'same-origin' }); |
| 56 | + const payload = await response.json() as AuthConfig & { error?: string }; |
| 57 | + if (!response.ok || !payload.supabaseUrl || !payload.supabaseAnonKey) throw new Error(payload.error ?? 'Organizer sign-in is not configured.'); |
| 58 | + return payload; |
| 59 | + } |
| 60 | + |
| 61 | + async function updateSession() { |
| 62 | + const response = await fetch('/api/auth/session', { credentials: 'same-origin' }); |
| 63 | + const session = await response.json() as { authenticated?: boolean; email?: string }; |
| 64 | + if (session.authenticated) { |
| 65 | + setMessage(`Signed in as ${session.email ?? 'an organizer'}.`); |
| 66 | + signIn?.setAttribute('hidden', ''); |
| 67 | + if (signOut) signOut.hidden = false; |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + signIn?.addEventListener('click', async () => { |
| 72 | + signIn.disabled = true; |
| 73 | + setMessage('Opening Google sign-in…'); |
| 74 | + try { |
| 75 | + const config = await authConfig(); |
| 76 | + const supabase = createClient(config.supabaseUrl, config.supabaseAnonKey, { |
| 77 | + auth: { persistSession: true, autoRefreshToken: false, detectSessionInUrl: false, flowType: 'pkce', storage: window.sessionStorage, storageKey: 'devcon-organizer-auth' }, |
| 78 | + }); |
| 79 | + const callbackUrl = new URL('/api/auth/admin/callback', window.location.origin); |
| 80 | + const { error } = await supabase.auth.signInWithOAuth({ provider: 'google', options: { redirectTo: callbackUrl.toString(), scopes: 'email profile', queryParams: { prompt: 'select_account' } } }); |
| 81 | + if (error) throw error; |
| 82 | + } catch (error) { |
| 83 | + setMessage(error instanceof Error ? error.message : 'Unable to start Google sign-in. Please try again.'); |
| 84 | + signIn.disabled = false; |
| 85 | + } |
| 86 | + }); |
| 87 | + |
| 88 | + signOut?.addEventListener('click', async () => { |
| 89 | + signOut.disabled = true; |
| 90 | + await fetch('/api/auth/logout', { method: 'POST', credentials: 'same-origin' }); |
| 91 | + window.location.replace('/'); |
| 92 | + }); |
| 93 | + |
| 94 | + void updateSession(); |
| 95 | +</script> |
0 commit comments