flotilla/src/app/components/SignUp.svelte

101 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-02-04 03:28:29 +00:00
import {isMobile, 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"
2024-11-27 00:39:49 +00:00
import SignUpSuccess from "@app/components/SignUpSuccess.svelte"
2025-01-28 21:04:37 +00:00
import {pushModal} from "@app/modal"
import {BURROW_URL, PLATFORM_NAME} from "@app/state"
2024-08-16 22:17:30 +00:00
import {pushToast} from "@app/toast"
2024-12-03 00:21:54 +00:00
2025-01-28 21:04:37 +00:00
const ac = window.location.origin
2024-12-03 00:21:54 +00:00
2025-01-28 21:04:37 +00:00
const at = isMobile ? "android" : "web"
2024-12-03 00:21:54 +00:00
2025-01-28 21:04:37 +00:00
const nstart = `https://start.njump.me/?an=Flotilla&at=${at}&ac=${ac}`
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
2024-11-27 00:39:49 +00:00
const signup = () => {
if (BURROW_URL) {
2024-11-27 17:12:27 +00:00
signupPassword()
2024-08-16 22:17:30 +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-04 00:37:14 +00:00
<form class="column gap-4" onsubmit={preventDefault(signup)}>
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
<Button class="link" onclick={() => pushModal(InfoNostr)}>nostr protocol</Button>, which allows
2024-08-16 22:17:30 +00:00
you to own your social identity.
</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-01-28 21:04:37 +00:00
<a href={nstart} class="btn {email || password ? 'btn-neutral' : 'btn-primary'}">
2024-10-30 17:07:54 +00:00
<Icon icon="square-share-line" />
2025-01-29 15:52:24 +00:00
Get going on nstart
2025-01-28 21:04:37 +00:00
</a>
<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>