Files
classroomio/src/routes/signup.svelte
T

139 lines
3.7 KiB
Svelte
Raw Normal View History

2021-07-31 23:06:14 +03:00
<script context="module">
export function preload(page, { config }) {
return { config };
}
</script>
2021-07-26 02:31:00 +03:00
<script>
2022-11-28 11:23:46 +01:00
import { Chasing } from 'svelte-loading-spinners';
2021-07-26 02:31:00 +03:00
import TextField from '../components/Form/TextField.svelte';
import PrimaryButton from '../components/PrimaryButton/index.svelte';
2021-07-31 23:06:14 +03:00
import { getSupabase } from '../utils/functions/supabase';
2022-11-28 11:23:46 +01:00
import { user } from '../utils/store/user';
import AuthUI from '../components/AuthUI/index.svelte';
2021-07-31 23:06:14 +03:00
export let config;
let supabase = getSupabase(config);
2021-07-26 02:31:00 +03:00
let email;
2022-11-28 11:23:46 +01:00
let name;
let password;
let passwordAgain;
let loading = false;
let success = false;
let errors = {};
2021-07-26 02:31:00 +03:00
2021-07-26 07:49:05 +03:00
async function handleSubmit() {
2022-11-28 11:23:46 +01:00
if (!email) {
errors = {
email: 'Email is required',
password: 'Password is required',
};
return;
}
2021-07-26 07:49:05 +03:00
try {
loading = true;
2022-11-28 11:23:46 +01:00
const { data, error } = await supabase.auth.signIn(
{ email },
{
redirectTo: window.location.origin + '/login',
}
);
2021-07-26 07:49:05 +03:00
if (error) throw error;
2022-11-28 11:23:46 +01:00
success = true;
email = {};
2021-07-26 07:49:05 +03:00
} catch (error) {
2022-11-28 11:23:46 +01:00
errors = {
email: error.error_description || error.message,
};
2021-07-26 07:49:05 +03:00
} finally {
loading = false;
}
2021-07-26 02:31:00 +03:00
}
</script>
<svelte:head>
2022-11-28 11:23:46 +01:00
<title>Sign Up - ClassroomIO</title>
2021-07-26 02:31:00 +03:00
</svelte:head>
2022-11-28 11:23:46 +01:00
<AuthUI {supabase} isLogin={false} {handleSubmit}>
<div class="mt-4 w-full">
{#if $user.fetchingUser}
<div class="h-40 text-md flex items-center justify-center">
<Chasing size="60" color="#ff3e00" unit="px" duration="1s" />
</div>
{:else if success}
<div class="h-40 text-md flex items-center justify-center flex-col">
<p class="">
A link has been sent to your email. Please check both your
<strong>spam </strong>and your<strong>&nbsp; inbox</strong>.
</p>
<p class="mt-2 underline">
If our email is in your spam, do make sure you mark our email address
as safe, then move it from your spam to your inbox.
2021-07-26 02:31:00 +03:00
</p>
</div>
2022-11-28 11:23:46 +01:00
{:else}
<p class="text-lg font-semibold mb-6">Create a free account</p>
<TextField
label="Full Name"
bind:value={name}
type="text"
autoFocus={true}
placeholder="e.g Joke Silva"
className="mb-6"
inputClassName="w-full"
isDisabled={loading}
errorMessage={errors.name}
/>
<TextField
label="Your Email"
bind:value={email}
type="email"
placeholder="you@domain.com"
className="mb-6"
inputClassName="w-full"
isDisabled={loading}
errorMessage={errors.email}
/>
<TextField
label="Your Password"
bind:value={password}
type="password"
placeholder="************"
className="mb-6"
inputClassName="w-full"
isDisabled={loading}
errorMessage={errors.password}
/>
<TextField
label="Confirm Password"
bind:value={passwordAgain}
type="password"
placeholder="************"
className="mb-6"
inputClassName="w-full"
isDisabled={loading}
errorMessage={errors.passwordAgain}
/>
<div class="w-full text-right">
<a class="text-md text-blue-700" href="/forgot"> Forgot password? </a>
2021-07-26 02:31:00 +03:00
</div>
2022-11-28 11:23:46 +01:00
{/if}
2021-07-26 02:31:00 +03:00
</div>
2022-11-28 11:23:46 +01:00
{#if !success}
<div class="my-4 w-full flex justify-end items-center">
<!-- <a href="/login" class="text-blue-700 text-sm">Create an account</a> -->
<PrimaryButton
label={loading ? 'Creating...' : 'Log In'}
type="submit"
className="py-3 sm:w-full w-full"
isDisabled={loading}
/>
</div>
{/if}
</AuthUI>