Files
classroomio/src/lib/components/AuthUI/index.svelte
T

81 lines
2.4 KiB
Svelte
Raw Normal View History

2022-11-28 11:23:46 +01:00
<script>
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
2022-11-28 11:23:46 +01:00
import GoogleIconColored from '../Icons/GoogleIconColored.svelte';
export let supabase;
export let handleSubmit;
export let isLogin = true;
2022-11-30 09:18:41 +01:00
export let showOnlyContent = false;
2023-08-04 12:49:34 +01:00
export let isLoading = false;
2022-12-03 22:45:01 +01:00
export let showLogo = false;
export let formRef;
2022-11-28 11:23:46 +01:00
async function signInWithGoogle() {
2023-08-04 12:49:34 +01:00
if (isLoading) {
return;
}
2022-12-03 22:45:01 +01:00
try {
console.log('signInWithGoogle');
const { user, session, error } = await supabase.auth.signInWithOAuth({
2023-08-04 12:49:34 +01:00
provider: 'google'
2022-12-03 22:45:01 +01:00
});
console.log('user', user);
console.log('session', session);
2022-12-03 22:45:01 +01:00
console.log('error', error);
} catch (error) {
console.log('catch error', error);
}
2022-11-28 11:23:46 +01:00
}
</script>
<div class="w-full min-h-screen flex items-center justify-center mt-4">
<div class="container border border-gray bg-white dark:bg-gray-800">
<div class="flex items-center flex-col p-2 lg:px-8 lg:py-3">
2022-12-03 22:45:01 +01:00
{#if !showOnlyContent || showLogo}
<div class="flex items-center w-full justify-center pt-4">
2023-08-04 12:49:34 +01:00
<img src="/logo-192.png" alt="ClassroomIO logo" height="50" width="50" data-atf="1" />
<h4 class="dark:text-white text-xl">ClassroomIO</h4>
2022-11-30 09:18:41 +01:00
</div>
{/if}
2022-11-28 11:23:46 +01:00
<form
2022-12-03 22:45:01 +01:00
bind:this={formRef}
2022-11-28 11:23:46 +01:00
on:submit|preventDefault={handleSubmit}
class="flex items-center flex-col w-10/12"
>
<slot />
</form>
2022-11-30 09:18:41 +01:00
{#if !showOnlyContent}
<div class="w-10/12 mb-3">
<p class="dark:text-white text-sm mb-5">or sign up with:</p>
2022-11-30 09:18:41 +01:00
<PrimaryButton
variant={VARIANTS.OUTLINED}
onClick={signInWithGoogle}
2023-08-04 12:49:34 +01:00
isDisabled={isLoading}
2022-11-30 09:18:41 +01:00
className="py-3 sm:w-full w-full"
>
<GoogleIconColored />
2023-08-04 12:49:34 +01:00
<span class="ml-2">{isLogin ? 'Sign in' : 'Sign up'} with Google</span>
2022-11-30 09:18:41 +01:00
</PrimaryButton>
</div>
2022-11-28 11:23:46 +01:00
{/if}
</div>
2022-11-30 09:18:41 +01:00
{#if !showOnlyContent}
<div class="w-full p-6 border-t border-grey text-center">
{#if isLogin}
2023-08-04 12:49:34 +01:00
Not registered yet? <a class="hover:underline text-blue-700" href="/signup">Sign up</a>
2022-11-30 09:18:41 +01:00
{:else}
2023-08-04 12:49:34 +01:00
Already have an account? <a class="hover:underline text-blue-700" href="/login">Log In</a>
2022-11-30 09:18:41 +01:00
{/if}
</div>
{/if}
2022-11-28 11:23:46 +01:00
</div>
</div>
<style>
.container {
width: 450px;
}
</style>