Added optional Discourse SSO.
This commit is contained in:
parent
5527c1eb91
commit
54da04763f
8 changed files with 337 additions and 8 deletions
|
|
@ -1,13 +1,23 @@
|
|||
<script>
|
||||
import { onMount } from 'svelte'
|
||||
import { api } from '../api.js'
|
||||
import { saveSession } from '../db.js'
|
||||
|
||||
let { onlogin } = $props()
|
||||
let { onlogin, error: initialError = '' } = $props()
|
||||
|
||||
let email = $state('')
|
||||
let password = $state('')
|
||||
let error = $state('')
|
||||
let error = $state(initialError)
|
||||
let loading = $state(false)
|
||||
let ssoEnabled = $state(false)
|
||||
let ssoLoading = $state(false)
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const res = await api.sso.enabled()
|
||||
ssoEnabled = res.enabled
|
||||
} catch {}
|
||||
})
|
||||
|
||||
async function submit(e) {
|
||||
e.preventDefault()
|
||||
|
|
@ -23,6 +33,18 @@
|
|||
loading = false
|
||||
}
|
||||
}
|
||||
|
||||
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
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="login-wrap">
|
||||
|
|
@ -45,5 +67,28 @@
|
|||
{loading ? 'Signing in…' : 'Sign in'}
|
||||
</button>
|
||||
</form>
|
||||
{#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}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<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>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue