61 lines
5.0 KiB
Vue
61 lines
5.0 KiB
Vue
<script setup lang="ts">
|
|
import { Label } from "@/components/ui/label";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import Logo from "@/components/topbar/Logo.vue";
|
|
import { computed, ref } from "vue";
|
|
import { Card } from "@/components/ui/card";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { api } from "@/lib/api";
|
|
import { passkeysAvailable, useAccountsStore, usePasskey } from "./accounts";
|
|
const accounts=useAccountsStore();
|
|
const step=ref(1);const recovery=ref(false);const recoveryCode=ref("");
|
|
const organisation=ref("");const workspace=ref("Default");const publicURL=ref(window.location.origin);
|
|
const name=ref("");const email=ref("");const password=ref("");const busy=ref(false);const error=ref("");
|
|
const setup=computed(()=>accounts.status?.setup_required===true);
|
|
const passkey=computed(()=>passkeysAvailable(accounts.status?.public_url??""));
|
|
async function submit(){
|
|
if(setup.value&&step.value===1&&!recovery.value){step.value=2;return}
|
|
busy.value=true;error.value="";
|
|
try{
|
|
if(recovery.value){await api.recoverAccount(email.value,recoveryCode.value,password.value);recovery.value=false;password.value="";error.value="Password changed. Sign in with your new password.";return}
|
|
if(setup.value)await api.setupAccount({organisation_name:organisation.value,workspace_name:workspace.value,public_url:publicURL.value.replace(/\/$/,""),display_name:name.value,email:email.value,password:password.value});
|
|
else await api.signIn(email.value,password.value);
|
|
password.value="";
|
|
window.location.assign(setup.value?"/account?welcome=1":new URLSearchParams(window.location.search).has("reauth")?"/account":"/");
|
|
}catch(cause){error.value=String((cause as Error).message||cause);await accounts.load()}
|
|
finally{busy.value=false}
|
|
}
|
|
async function signInPasskey(){busy.value=true;error.value="";try{await usePasskey(false);window.location.assign("/")}catch(cause){error.value=String((cause as Error).message||cause)}finally{busy.value=false}}
|
|
</script>
|
|
<template>
|
|
<main class="mx-auto flex min-h-[90dvh] max-w-md flex-col justify-center px-5 py-10">
|
|
<Card class="gap-0 py-6 px-6 shadow-sm">
|
|
<div class="mb-2"><Logo /></div>
|
|
<h1 class="text-2xl font-medium">{{setup?(step===1?'Set up your organisation':'Create your admin account'):recovery?'Recover your account':'Sign in'}}</h1>
|
|
<form class="mt-6 space-y-4" @submit.prevent="submit">
|
|
<template v-if="setup&&step===1">
|
|
<Label class="block space-y-1.5 text-sm" for="organisation">Organisation name<Input id="organisation" v-model="organisation" autocomplete="organization" required maxlength="200" /></Label>
|
|
<Label class="block space-y-1.5 text-sm" for="workspace">First workspace<Input id="workspace" v-model="workspace" required maxlength="200" /></Label>
|
|
<Label class="block space-y-1.5 text-sm" for="public-url">Instance URL<Input id="public-url" v-model="publicURL" type="url" required autocomplete="url" /></Label>
|
|
<p class="text-xs text-fg-muted">Use the address people will visit. Passkeys require HTTPS and a domain name, or localhost for development.</p>
|
|
</template>
|
|
<template v-else>
|
|
<Label v-if="setup" class="block space-y-1.5 text-sm" for="account-name">Your name<Input id="account-name" v-model="name" autocomplete="name" required maxlength="200" /></Label>
|
|
<Label class="block space-y-1.5 text-sm" for="account-email">Email<Input id="account-email" v-model="email" type="email" autocomplete="username" :spellcheck="false" required /></Label>
|
|
<Label v-if="recovery" class="block space-y-1.5 text-sm" for="recovery-code">Recovery code<Input id="recovery-code" v-model="recoveryCode" autocomplete="off" required /></Label>
|
|
<Label class="block space-y-1.5 text-sm" for="account-password">{{recovery?"New password":"Password"}}<Input id="account-password" v-model="password" type="password" :autocomplete="setup||recovery?'new-password':'current-password'" :minlength="setup||recovery?15:undefined" maxlength="1024" required /></Label>
|
|
<p v-if="setup" class="text-xs text-fg-muted">At least 15 characters.</p>
|
|
</template>
|
|
<Alert v-if="error" variant="destructive"><AlertDescription>{{error}}</AlertDescription></Alert>
|
|
<div class="flex gap-2"><Button v-if="setup&&step===2" type="button" variant="outline" :disabled="busy" @click="step=1">Back</Button><Button type="submit" class="flex-1" :disabled="busy">{{busy?'Please wait…':setup?(step===1?'Continue':'Create organisation and admin'):recovery?'Reset password':'Sign in'}}</Button></div>
|
|
</form>
|
|
<div v-if="!setup&&!recovery" class="mt-4 flex flex-col gap-2">
|
|
<Button v-if="passkey" variant="outline" :disabled="busy" @click="signInPasskey">Sign in with a passkey</Button>
|
|
<Button v-if="accounts.status?.oidc" variant="outline" as-child><a href="/oauth2/login">Sign in with OIDC</a></Button>
|
|
</div>
|
|
<Button v-if="!setup" variant="link" class="mt-3" :disabled="busy" @click="recovery=!recovery;error=''">{{recovery?'Back to sign in':'Use a recovery code'}}</Button>
|
|
</Card>
|
|
</main>
|
|
</template>
|