Files
classroomio/src/routes/login.svelte
T

117 lines
3.1 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-04-05 07:12:51 +03:00
<script>
2021-08-18 19:47:02 +03: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';
2021-08-18 19:47:02 +03:00
import { user } from '../utils/store/user';
2022-11-28 11:23:46 +01:00
import AuthUI from '../components/AuthUI/index.svelte';
2021-07-26 02:31:00 +03:00
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 password;
2021-07-31 23:06:14 +03:00
let loading = false;
let success = false;
let errors = {};
2021-07-26 02:31:00 +03:00
2021-07-31 23:06:14 +03:00
async function handleSubmit() {
if (!email) {
errors = {
email: 'Email is required',
2022-11-28 11:23:46 +01:00
password: 'Password is required',
2021-07-31 23:06:14 +03:00
};
return;
}
try {
loading = true;
const { data, error } = await supabase.auth.signIn(
{ email },
{
redirectTo: window.location.origin + '/login',
}
);
if (error) throw error;
success = true;
email = {};
} catch (error) {
errors = {
email: error.error_description || error.message,
};
} finally {
loading = false;
}
2021-04-05 07:12:51 +03:00
}
</script>
2021-01-21 22:26:32 +02:00
<svelte:head>
2022-11-28 11:23:46 +01:00
<title>Login - ClassroomIO</title>
2021-01-21 22:26:32 +02:00
</svelte:head>
2022-11-28 11:23:46 +01:00
<AuthUI {supabase} isLogin={true} {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" />
2021-07-26 02:31:00 +03:00
</div>
2022-11-28 11:23:46 +01:00
{: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.
</p>
</div>
{:else}
<p class="text-lg font-semibold mb-6">Welcome back</p>
<TextField
label="Your email"
bind:value={email}
type="email"
autoFocus={true}
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}
/>
<div class="w-full text-right">
<a class="text-md text-blue-700" href="/forgot"> Forgot password? </a>
</div>
{/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>