diff --git a/src/components/AuthUI/index.svelte b/src/components/AuthUI/index.svelte index 757aa4f6..8cbe02f2 100644 --- a/src/components/AuthUI/index.svelte +++ b/src/components/AuthUI/index.svelte @@ -6,6 +6,7 @@ export let supabase; export let handleSubmit; export let isLogin = true; + export let showOnlyContent = false; async function signInWithGoogle() { const { data, error } = await supabase.auth.signInWithOAuth({ @@ -15,49 +16,57 @@
-
+
-
- ClassroomIO logo -

ClassroomIO

-
+ {#if !showOnlyContent} +
+ ClassroomIO logo +

ClassroomIO

+
+ {/if}
-
-

or sign up with:

- - - Sign up with Google - -
-
-
- {#if isLogin} - Not registered yet? Sign up - {:else} - Already have an account? Log In + {#if !showOnlyContent} +
+

or sign up with:

+ + + Sign up with Google + +
{/if}
+ {#if !showOnlyContent} +
+ {#if isLogin} + Not registered yet? Sign up + {:else} + Already have an account? Log In + {/if} +
+ {/if}
diff --git a/src/components/Icons/EmailSentIcon.svelte b/src/components/Icons/EmailSentIcon.svelte new file mode 100644 index 00000000..59106fdc --- /dev/null +++ b/src/components/Icons/EmailSentIcon.svelte @@ -0,0 +1,44 @@ + + + + + + + diff --git a/src/routes/_layout.svelte b/src/routes/_layout.svelte index baa2c57e..4e961c23 100644 --- a/src/routes/_layout.svelte +++ b/src/routes/_layout.svelte @@ -37,9 +37,9 @@ }); async function getProfile() { - console.log('Get user profile'); // Get user profile const authUser = supabase.auth.user(); + console.log('Get user profile', authUser); // Check if user has profile let { @@ -82,6 +82,7 @@ goto('/dashboard'); } } + $user.fetchingUser = false; } else if (profileData) { // Profile exists, go to profile page $user.fetchingUser = false; diff --git a/src/routes/signup.svelte b/src/routes/signup.svelte index e5591f53..578d748a 100644 --- a/src/routes/signup.svelte +++ b/src/routes/signup.svelte @@ -5,81 +5,92 @@ Sign Up - ClassroomIO - +
{#if $user.fetchingUser}
{:else if success} -
-

- A link has been sent to your email. Please check both your +

+ +

Email sent!

+

+ We have sent a confirmation email to {fields.email}. Please check both + your spam and your  inbox.

-

- 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. -

{:else}

Create a free account

+ {#if submitError} +

{submitError}

+ {/if} @@ -126,12 +145,11 @@ {#if !success}
-
{/if} diff --git a/src/utils/constants/authentication.js b/src/utils/constants/authentication.js new file mode 100644 index 00000000..744491e2 --- /dev/null +++ b/src/utils/constants/authentication.js @@ -0,0 +1,6 @@ +export const SIGNUP_FIELDS = { + name: '', + email: '', + password: '', + confirmPassword: '', +}; diff --git a/src/utils/functions/validator.js b/src/utils/functions/validator.js new file mode 100644 index 00000000..a53661d9 --- /dev/null +++ b/src/utils/functions/validator.js @@ -0,0 +1,43 @@ +import z from 'zod'; + +const validationSchema = z.object({ + name: z.string().min(3, { + message: 'Must be 3 or more characters long', + invalid_type_error: 'Must not be empty', + }), + email: z.string().email({ + message: 'Invalid email address', + invalid_type_error: 'Must not be empty', + }), + password: z.string().min(6, { + message: 'Must be 6 or more characters long', + invalid_type_error: 'Must not be empty', + }), +}); + +export const getConfirmPasswordError = ({ password, confirmPassword }) => { + return password > 6 && confirmPassword > 6 && password !== confirmPassword + ? 'Does not match password' + : null; +}; + +export const signUpValidation = (fields = {}) => { + const { error } = validationSchema.safeParse(fields); + const errors = {}; + + if (Array.isArray(error?.issues)) { + for (const issue of error.issues) { + const { message, path } = issue; + console.log(issue); + if (path.length) { + errors[path[0]] = message; + } + } + } + + return errors; +}; + +export const getDisableSubmit = ({ password, confirmPassword }) => { + return !!(password && confirmPassword && password !== confirmPassword); +};