# Authentication - Supabase

Authentication is handled by Supabase which is a requirement for this project.

Authentication functions are primarily located src/routes/login.svelte with the user account details being saved to to the session store in src/routes/+page.svelte. The session store is then used to access user details.

Whenever the Supbase user state changes, src/routes/+page.svelte updates the user session store and shows the appropiate page.

# handleSignUp()

Description

Signs the user up & then logs the user in if password meets threshold & matches the repeat password field.

Parameters

None

Name Type Description Default
A B C D

Returns

None

Type Description
A B

Raises

None

Type Description
A B

::: details source code in src/routes/login.svelte

  const handleSignUp = async () => {
      if (!is_valid_password(register_password)) {document.getElementById("registerPassword").focus(); return;};
      if (register_password !== register_repeat_password) {document.getElementById("registerRepeatPassword").focus(); return;};

      try {
        loading = true;
        const { user1, session1, error1 } = await supabase.auth.signUp(
          {
            email: register_email,
            password: register_password,
          }, { 
              redirectTo: window.location.href, 
          }
        );

        if (error1) {
          throw error1;
        } else {

          const { user2, session, error2 } = await supabase.auth.signIn({
            email: login_email,
            password: login_password,
          });

          if (error2) throw error2;
        }

        
      } catch (error) {
        alert(error.error_description || error.message);
      } finally {
        loading = false;
      }
    }

:::