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

97 lines
2.9 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';
2023-08-17 14:05:01 +01:00
import Avatar from '$lib/components/Avatar/index.svelte';
import { currentOrg } from '$lib/utils/store/org';
2022-11-28 11:23:46 +01:00
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="root w-full min-h-screen flex items-center justify-center">
<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}
2023-08-18 08:28:18 +01:00
<div class="flex items-center justify-center w-full pt-2">
2023-08-17 14:05:01 +01:00
<Avatar
src={$currentOrg.avatar_url ? $currentOrg.avatar_url : '/logo-192.png'}
name={$currentOrg.name ? $currentOrg.name : 'ClassroomIO'}
shape="rounded-md"
width="w-10"
height="h-10"
2023-08-18 08:28:18 +01:00
className="mr-2"
2023-08-17 14:05:01 +01:00
/>
2023-08-18 08:28:18 +01:00
<h4 class="dark:text-white text-xl">
2023-08-17 14:05:01 +01:00
{$currentOrg.name ? $currentOrg.name : '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-20 19:08:48 +00:00
Not registered yet? <a class="hover:underline text-primary-700" href="/signup">Sign up</a>
2022-11-30 09:18:41 +01:00
{:else}
2023-08-20 19:08:48 +00:00
Already have an account? <a class="hover:underline text-primary-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>
.root {
background: radial-gradient(circle at 10% 20%, rgb(239, 246, 249) 0%, rgb(206, 239, 253) 90%);
}
2022-11-28 11:23:46 +01:00
.container {
width: 450px;
}
</style>