flotilla/src/app/components/SignUp.svelte

98 lines
3.1 KiB
Svelte
Raw Normal View History

2024-08-16 22:17:30 +00:00
<script lang="ts">
2025-01-28 21:04:37 +00:00
import {postJson} from "@welshman/lib"
2025-08-18 22:02:17 +00:00
import {preventDefault} from "@lib/html"
2024-08-16 22:17:30 +00:00
import Icon from "@lib/components/Icon.svelte"
2024-11-27 00:39:49 +00:00
import FieldInline from "@lib/components/FieldInline.svelte"
2024-08-16 22:17:30 +00:00
import Button from "@lib/components/Button.svelte"
import Divider from "@lib/components/Divider.svelte"
2024-08-16 22:17:30 +00:00
import Spinner from "@lib/components/Spinner.svelte"
import LogIn from "@app/components/LogIn.svelte"
import InfoNostr from "@app/components/InfoNostr.svelte"
2025-08-18 22:02:17 +00:00
import SignUpProfile from "@app/components/SignUpProfile.svelte"
2024-11-27 00:39:49 +00:00
import SignUpSuccess from "@app/components/SignUpSuccess.svelte"
import {pushModal} from "@app/util/modal"
import {BURROW_URL, PLATFORM_NAME} from "@app/core/state"
import {pushToast} from "@app/util/toast"
2024-12-03 00:21:54 +00:00
2024-08-16 22:17:30 +00:00
const login = () => pushModal(LogIn)
2025-01-28 21:04:37 +00:00
const signupPassword = async () => {
loading = true
2024-11-27 00:39:49 +00:00
2025-01-28 21:04:37 +00:00
try {
const res = await postJson(BURROW_URL + "/user", {email, password})
2024-12-03 00:21:54 +00:00
2025-01-28 21:04:37 +00:00
if (res.error) {
pushToast({message: res.error, theme: "error"})
} else {
pushModal(SignUpSuccess, {email}, {replaceState: true})
}
} finally {
loading = false
2024-08-16 22:17:30 +00:00
}
2025-01-28 21:04:37 +00:00
}
2024-08-16 22:17:30 +00:00
2025-02-14 18:53:36 +00:00
const usePassword = () => {
2024-11-27 00:39:49 +00:00
if (BURROW_URL) {
2024-11-27 17:12:27 +00:00
signupPassword()
2024-08-16 22:17:30 +00:00
}
}
2025-08-18 22:02:17 +00:00
const next = () => pushModal(SignUpProfile)
2025-02-14 18:53:36 +00:00
2025-02-04 00:37:14 +00:00
let email = $state("")
let password = $state("")
let loading = $state(false)
2024-08-16 22:17:30 +00:00
</script>
2025-02-14 18:53:36 +00:00
<form class="column gap-4" onsubmit={preventDefault(usePassword)}>
2024-08-16 22:17:30 +00:00
<h1 class="heading">Sign up with Nostr</h1>
<p class="m-auto max-w-sm text-center">
2024-10-22 18:04:40 +00:00
{PLATFORM_NAME} is built using the
2025-08-18 22:02:17 +00:00
<Button class="link" onclick={() => pushModal(InfoNostr)}>nostr protocol</Button>, which gives
users control over their digital identity using <strong>cryptographic key pairs</strong>.
2024-08-16 22:17:30 +00:00
</p>
2024-11-27 00:39:49 +00:00
{#if BURROW_URL}
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Email</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="user-rounded" />
<input bind:value={email} />
</label>
{/snippet}
2024-11-27 00:39:49 +00:00
</FieldInline>
<FieldInline>
2025-02-04 00:37:14 +00:00
{#snippet label()}
<p>Password</p>
{/snippet}
{#snippet input()}
<label class="input input-bordered flex w-full items-center gap-2">
<Icon icon="key" />
<input bind:value={password} type="password" />
</label>
{/snippet}
2024-11-27 00:39:49 +00:00
</FieldInline>
<Button type="submit" class="btn btn-primary" disabled={loading || !email || !password}>
<Spinner {loading}>Sign Up</Spinner>
<Icon icon="alt-arrow-right" />
</Button>
<p class="text-sm opacity-75">
Note that your email and password will only work to log in to {PLATFORM_NAME}. To use your key
on other nostr applications, you can create a nostr key yourself, or export your key from {PLATFORM_NAME}
later.
</p>
2025-01-28 21:04:37 +00:00
<Divider>Or</Divider>
2024-11-27 00:39:49 +00:00
{/if}
2025-08-18 22:02:17 +00:00
<Button onclick={next} class="btn {email || password ? 'btn-neutral' : 'btn-primary'}">
<Icon icon="key" />
Generate a key
</Button>
<div class="text-sm">
Already have an account?
<Button class="link" onclick={login}>Log in instead</Button>
2024-08-16 22:17:30 +00:00
</div>
</form>