2026-03-03 11:27:07 -06:00
|
|
|
<script>
|
2026-03-10 17:45:38 -05:00
|
|
|
import { onMount } from 'svelte'
|
2026-03-03 11:27:07 -06:00
|
|
|
import { api } from '../api.js'
|
|
|
|
|
import { saveSession } from '../db.js'
|
|
|
|
|
|
2026-03-10 17:45:38 -05:00
|
|
|
let { onlogin, error: initialError = '' } = $props()
|
2026-03-03 11:27:07 -06:00
|
|
|
|
2026-03-10 14:08:00 -05:00
|
|
|
let email = $state('')
|
2026-03-03 11:27:07 -06:00
|
|
|
let password = $state('')
|
2026-03-10 17:45:38 -05:00
|
|
|
let error = $state(initialError)
|
2026-03-03 11:27:07 -06:00
|
|
|
let loading = $state(false)
|
2026-03-10 17:45:38 -05:00
|
|
|
let ssoEnabled = $state(false)
|
|
|
|
|
let ssoLoading = $state(false)
|
|
|
|
|
|
|
|
|
|
onMount(async () => {
|
|
|
|
|
try {
|
|
|
|
|
const res = await api.sso.enabled()
|
|
|
|
|
ssoEnabled = res.enabled
|
|
|
|
|
} catch {}
|
|
|
|
|
})
|
2026-03-03 11:27:07 -06:00
|
|
|
|
|
|
|
|
async function submit(e) {
|
|
|
|
|
e.preventDefault()
|
|
|
|
|
error = ''
|
|
|
|
|
loading = true
|
|
|
|
|
try {
|
2026-03-10 14:08:00 -05:00
|
|
|
const { token, user } = await api.login(email, password)
|
2026-03-03 11:27:07 -06:00
|
|
|
await saveSession(token, user)
|
|
|
|
|
onlogin({ token, user })
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error = err.message || 'Login failed'
|
|
|
|
|
} finally {
|
|
|
|
|
loading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-10 17:45:38 -05:00
|
|
|
|
|
|
|
|
async function startSSO() {
|
|
|
|
|
error = ''
|
|
|
|
|
ssoLoading = true
|
|
|
|
|
try {
|
|
|
|
|
const { redirect_url } = await api.sso.init()
|
|
|
|
|
window.location.href = redirect_url
|
|
|
|
|
} catch (err) {
|
|
|
|
|
error = err.message || 'SSO failed'
|
|
|
|
|
ssoLoading = false
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-03 11:27:07 -06:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<div class="login-wrap">
|
|
|
|
|
<div class="login-box">
|
|
|
|
|
<h1 class="login-title">Turnpike</h1>
|
|
|
|
|
<p class="login-sub">Event management</p>
|
|
|
|
|
{#if error}
|
|
|
|
|
<div class="alert alert-error">{error}</div>
|
|
|
|
|
{/if}
|
|
|
|
|
<form onsubmit={submit}>
|
|
|
|
|
<div class="form-group">
|
2026-03-10 14:08:00 -05:00
|
|
|
<label for="email">Email</label>
|
|
|
|
|
<input id="email" type="email" bind:value={email} autocomplete="email" required />
|
2026-03-03 11:27:07 -06:00
|
|
|
</div>
|
|
|
|
|
<div class="form-group">
|
|
|
|
|
<label for="password">Password</label>
|
|
|
|
|
<input id="password" type="password" bind:value={password} autocomplete="current-password" required />
|
|
|
|
|
</div>
|
|
|
|
|
<button type="submit" class="btn btn-primary" style="width:100%" disabled={loading}>
|
|
|
|
|
{loading ? 'Signing in…' : 'Sign in'}
|
|
|
|
|
</button>
|
|
|
|
|
</form>
|
2026-03-10 17:45:38 -05:00
|
|
|
{#if ssoEnabled}
|
|
|
|
|
<div class="sso-divider"><span>or</span></div>
|
|
|
|
|
<button class="btn btn-ghost" style="width:100%" onclick={startSSO} disabled={ssoLoading}>
|
|
|
|
|
{ssoLoading ? 'Redirecting…' : 'Log in with Discourse'}
|
|
|
|
|
</button>
|
|
|
|
|
{/if}
|
2026-03-03 11:27:07 -06:00
|
|
|
</div>
|
|
|
|
|
</div>
|
2026-03-10 17:45:38 -05:00
|
|
|
|
|
|
|
|
<style>
|
|
|
|
|
.sso-divider {
|
|
|
|
|
display: flex;
|
|
|
|
|
align-items: center;
|
|
|
|
|
margin: 1rem 0;
|
|
|
|
|
gap: 0.75rem;
|
|
|
|
|
color: var(--c-muted);
|
|
|
|
|
font-size: 0.8rem;
|
|
|
|
|
}
|
|
|
|
|
.sso-divider::before,
|
|
|
|
|
.sso-divider::after {
|
|
|
|
|
content: '';
|
|
|
|
|
flex: 1;
|
|
|
|
|
border-top: 1px solid var(--c-border);
|
|
|
|
|
}
|
|
|
|
|
</style>
|