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>
|
2023-07-18 07:40:12 +00:00
|
|
|
import { goto } from "@sapper/app";
|
|
|
|
|
import TextField from "../components/Form/TextField.svelte";
|
|
|
|
|
import PrimaryButton from "../components/PrimaryButton/index.svelte";
|
|
|
|
|
import { getSupabase } from "../utils/functions/supabase";
|
2022-11-30 09:18:41 +01:00
|
|
|
import {
|
2022-12-03 22:45:01 +01:00
|
|
|
authValidation,
|
2022-11-30 09:18:41 +01:00
|
|
|
getConfirmPasswordError,
|
|
|
|
|
getDisableSubmit,
|
2023-07-18 07:40:12 +00:00
|
|
|
} from "../utils/functions/validator";
|
|
|
|
|
import { SIGNUP_FIELDS } from "../utils/constants/authentication";
|
|
|
|
|
import AuthUI from "../components/AuthUI/index.svelte";
|
2022-11-28 11:23:46 +01:00
|
|
|
|
2021-07-31 23:06:14 +03:00
|
|
|
export let config;
|
|
|
|
|
|
|
|
|
|
let supabase = getSupabase(config);
|
2022-11-30 09:18:41 +01:00
|
|
|
let fields = Object.assign({}, SIGNUP_FIELDS);
|
2022-11-28 11:23:46 +01:00
|
|
|
let loading = false;
|
|
|
|
|
let success = false;
|
|
|
|
|
let errors = {};
|
2022-11-30 09:18:41 +01:00
|
|
|
let submitError;
|
|
|
|
|
let disableSubmit = false;
|
2022-12-03 22:45:01 +01:00
|
|
|
let formRef;
|
2021-07-26 02:31:00 +03:00
|
|
|
|
2022-12-03 22:45:01 +01:00
|
|
|
async function handleSubmit(e) {
|
|
|
|
|
const validationRes = authValidation(fields);
|
2023-07-18 07:40:12 +00:00
|
|
|
console.log("validationRes", validationRes);
|
2022-11-30 09:18:41 +01:00
|
|
|
|
|
|
|
|
if (Object.keys(validationRes).length) {
|
|
|
|
|
errors = Object.assign(errors, validationRes);
|
2022-11-28 11:23:46 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-26 07:49:05 +03:00
|
|
|
try {
|
|
|
|
|
loading = true;
|
2022-11-30 09:18:41 +01:00
|
|
|
const { data, error } = await supabase.auth.signUp({
|
|
|
|
|
email: fields.email,
|
|
|
|
|
password: fields.password,
|
|
|
|
|
});
|
2023-07-18 07:40:12 +00:00
|
|
|
console.log("data", data);
|
2021-07-26 07:49:05 +03:00
|
|
|
if (error) throw error;
|
2022-11-28 11:23:46 +01:00
|
|
|
|
2022-12-03 22:45:01 +01:00
|
|
|
formRef?.reset();
|
|
|
|
|
|
2023-07-18 07:40:12 +00:00
|
|
|
return goto("/login");
|
2022-11-30 09:18:41 +01:00
|
|
|
// success = true;
|
|
|
|
|
// fields = Object.assign({}, SIGNUP_FIELDS);
|
2021-07-26 07:49:05 +03:00
|
|
|
} catch (error) {
|
2022-11-30 09:18:41 +01:00
|
|
|
submitError = error.error_description || error.message;
|
2021-07-26 07:49:05 +03:00
|
|
|
} finally {
|
|
|
|
|
loading = false;
|
|
|
|
|
}
|
2021-07-26 02:31:00 +03:00
|
|
|
}
|
2022-11-30 09:18:41 +01:00
|
|
|
|
|
|
|
|
$: errors.confirmPassword = getConfirmPasswordError(fields);
|
|
|
|
|
$: disableSubmit = getDisableSubmit(fields);
|
2021-07-26 02:31:00 +03:00
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<svelte:head>
|
2022-12-03 22:45:01 +01:00
|
|
|
<title>Join ClassroomIO</title>
|
2021-07-26 02:31:00 +03:00
|
|
|
</svelte:head>
|
|
|
|
|
|
2022-12-03 22:45:01 +01:00
|
|
|
<AuthUI
|
|
|
|
|
{supabase}
|
|
|
|
|
isLogin={false}
|
|
|
|
|
{handleSubmit}
|
|
|
|
|
showOnlyContent={success}
|
|
|
|
|
bind:formRef
|
|
|
|
|
>
|
2022-11-28 11:23:46 +01:00
|
|
|
<div class="mt-4 w-full">
|
2023-05-05 20:19:45 +00:00
|
|
|
<p class="dark:text-white text-lg font-semibold mb-6">
|
|
|
|
|
Create a free account
|
|
|
|
|
</p>
|
2022-12-03 22:45:01 +01:00
|
|
|
<!-- <TextField
|
|
|
|
|
label="Full Name"
|
|
|
|
|
bind:value={fields.name}
|
|
|
|
|
type="text"
|
|
|
|
|
autoFocus={true}
|
|
|
|
|
placeholder="e.g Joke Silva"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
|
|
|
|
isDisabled={loading}
|
|
|
|
|
errorMessage={errors.name}
|
|
|
|
|
isRequired
|
|
|
|
|
/> -->
|
|
|
|
|
<TextField
|
|
|
|
|
label="Your Email"
|
|
|
|
|
bind:value={fields.email}
|
|
|
|
|
type="email"
|
|
|
|
|
placeholder="you@domain.com"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
|
|
|
|
isDisabled={loading}
|
|
|
|
|
errorMessage={errors.email}
|
|
|
|
|
isRequired
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
label="Your Password"
|
|
|
|
|
bind:value={fields.password}
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="************"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
|
|
|
|
isDisabled={loading}
|
|
|
|
|
errorMessage={errors.password}
|
|
|
|
|
helperMessage="Password must be more than 6 characters"
|
|
|
|
|
isRequired
|
|
|
|
|
/>
|
|
|
|
|
<TextField
|
|
|
|
|
label="Confirm Password"
|
|
|
|
|
bind:value={fields.confirmPassword}
|
|
|
|
|
type="password"
|
|
|
|
|
placeholder="************"
|
|
|
|
|
className="mb-6"
|
|
|
|
|
inputClassName="w-full"
|
|
|
|
|
isDisabled={loading}
|
|
|
|
|
errorMessage={errors.confirmPassword}
|
|
|
|
|
isRequired
|
|
|
|
|
/>
|
|
|
|
|
{#if submitError}
|
2023-05-11 15:15:18 +00:00
|
|
|
<p class="text-sm text-red-500">{submitError}</p>
|
2022-11-28 11:23:46 +01:00
|
|
|
{/if}
|
2021-07-26 02:31:00 +03:00
|
|
|
</div>
|
|
|
|
|
|
2022-12-03 22:45:01 +01:00
|
|
|
<div class="my-4 w-full flex justify-end items-center">
|
|
|
|
|
<PrimaryButton
|
|
|
|
|
label="Create Account"
|
|
|
|
|
type="submit"
|
|
|
|
|
className="sm:w-full w-full"
|
|
|
|
|
isDisabled={disableSubmit || loading}
|
|
|
|
|
isLoading={loading}
|
|
|
|
|
/>
|
|
|
|
|
</div>
|
2022-11-28 11:23:46 +01:00
|
|
|
</AuthUI>
|