2025-07-09 15:21:39 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-->
|
|
|
|
<template>
|
|
|
|
<main>
|
|
|
|
<h1>Register</h1>
|
2025-07-09 17:57:49 +02:00
|
|
|
<div class="card">
|
|
|
|
<h2>Regular User</h2>
|
2025-07-09 15:21:39 +02:00
|
|
|
<p>
|
2025-07-09 17:57:49 +02:00
|
|
|
Set up an authentication method and choose a username to register a new user.
|
2025-07-09 15:21:39 +02:00
|
|
|
</p>
|
2025-07-09 17:57:49 +02:00
|
|
|
<h3>Authentication Method</h3>
|
2025-07-09 15:21:39 +02:00
|
|
|
<p v-if="sessionStore.authenticationProvider">
|
|
|
|
Provider: {{ sessionStore.authenticationProvider }}
|
|
|
|
<br>Identifier: {{ sessionStore.authenticationName }}
|
|
|
|
<br><button type="button" @click="clearProvider">Clear Method</button>
|
|
|
|
</p>
|
2025-07-09 17:57:49 +02:00
|
|
|
<LogIn v-else />
|
|
|
|
<form @submit.prevent="register(false)">
|
|
|
|
<h3>User Details</h3>
|
|
|
|
<p>
|
|
|
|
<label>
|
|
|
|
Username
|
|
|
|
<input type="text" v-model="username" required>
|
|
|
|
</label>
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
<button
|
|
|
|
type="submit"
|
|
|
|
:disabled="!sessionStore.authenticationProvider"
|
|
|
|
>
|
|
|
|
Register new user
|
|
|
|
</button>
|
|
|
|
</p>
|
|
|
|
</form>
|
|
|
|
</div>
|
|
|
|
<div class="alternatively">
|
|
|
|
– or –
|
|
|
|
</div>
|
|
|
|
<div class="card">
|
|
|
|
<h2>Anonymous User</h2>
|
|
|
|
<p>
|
|
|
|
If you do not wish to deal with logins you may create an
|
|
|
|
anonymous user authenticated with a session cookie stored on
|
|
|
|
this device. Since there's no persistent authentication for the
|
|
|
|
user should you lose the session cookie you will also lose
|
|
|
|
access to the user.
|
2025-07-09 15:21:39 +02:00
|
|
|
</p>
|
|
|
|
<p>
|
2025-07-09 17:57:49 +02:00
|
|
|
<button type="button" @click="register(true)">
|
|
|
|
Create anonymous user
|
|
|
|
</button>
|
2025-07-09 15:21:39 +02:00
|
|
|
</p>
|
2025-07-09 17:57:49 +02:00
|
|
|
</div>
|
2025-07-09 15:21:39 +02:00
|
|
|
</main>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
2025-07-09 17:57:49 +02:00
|
|
|
useHead({
|
|
|
|
title: "Register",
|
|
|
|
});
|
|
|
|
|
2025-07-09 15:21:39 +02:00
|
|
|
const sessionStore = useSessionStore();
|
|
|
|
const username = ref("");
|
|
|
|
|
|
|
|
async function clearProvider() {
|
|
|
|
sessionStore.logOut();
|
|
|
|
}
|
2025-07-09 17:57:49 +02:00
|
|
|
async function register(anonymous: boolean) {
|
2025-07-09 15:21:39 +02:00
|
|
|
let session;
|
|
|
|
try {
|
|
|
|
session = await $fetch("/api/auth/account", {
|
|
|
|
method: "POST",
|
2025-07-09 17:57:49 +02:00
|
|
|
body: anonymous ? undefined : {
|
2025-07-09 15:21:39 +02:00
|
|
|
name: username.value,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
} catch (err: any) {
|
|
|
|
alert(err.data?.message ?? err.message);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sessionStore.update(session);
|
|
|
|
if (session.account) {
|
|
|
|
await navigateTo("/account/settings");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
2025-07-09 17:57:49 +02:00
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
.alternatively {
|
|
|
|
margin-block: 1rem;
|
|
|
|
}
|
|
|
|
.card {
|
|
|
|
background: color-mix(in oklab, var(--background), grey 20%);
|
|
|
|
padding: 0.5rem;
|
|
|
|
border-radius: 0.5rem;
|
|
|
|
}
|
|
|
|
.card h2 {
|
|
|
|
margin-block-start: 0;
|
|
|
|
}
|
|
|
|
</style>
|