2023-09-14 06:42:16 +01:00
|
|
|
<script lang="ts">
|
|
|
|
|
import { page } from '$app/stores';
|
2023-08-02 19:35:27 +01:00
|
|
|
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';
|
2023-09-14 06:42:16 +01:00
|
|
|
import type { SupabaseClient } from '@supabase/supabase-js';
|
2022-11-28 11:23:46 +01:00
|
|
|
|
2023-09-14 06:42:16 +01:00
|
|
|
export let supabase: SupabaseClient;
|
|
|
|
|
export let handleSubmit = () => {};
|
2022-11-28 11:23:46 +01:00
|
|
|
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;
|
2023-09-14 06:42:16 +01:00
|
|
|
export let hideGoogleAuth = false;
|
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');
|
2023-09-14 06:42:16 +01:00
|
|
|
const { error, data } = await supabase.auth.signInWithOAuth({
|
2023-08-04 12:49:34 +01:00
|
|
|
provider: 'google'
|
2022-12-03 22:45:01 +01:00
|
|
|
});
|
|
|
|
|
|
2023-09-14 06:42:16 +01:00
|
|
|
console.log('data', data);
|
2022-12-03 22:45:01 +01:00
|
|
|
console.log('error', error);
|
2022-12-04 05:28:34 +01:00
|
|
|
} catch (error) {
|
|
|
|
|
console.log('catch error', error);
|
|
|
|
|
}
|
2022-11-28 11:23:46 +01:00
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
2023-08-18 19:28:41 +00:00
|
|
|
<div class="root w-full min-h-screen flex items-center justify-center">
|
2023-09-16 22:44:20 +01:00
|
|
|
<div class="container border border-gray bg-white dark:bg-black">
|
2022-12-30 13:08:54 +01:00
|
|
|
<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-24 09:12:10 +01:00
|
|
|
<div class="flex flex-col 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-24 09:12:10 +01:00
|
|
|
<h4 class="dark:text-white text-xl mt-0">
|
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>
|
2023-09-14 06:42:16 +01:00
|
|
|
{#if !showOnlyContent && !hideGoogleAuth}
|
2022-11-30 09:18:41 +01:00
|
|
|
<div class="w-10/12 mb-3">
|
2023-05-05 20:19:45 +00:00
|
|
|
<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-09-14 06:42:16 +01:00
|
|
|
Not registered yet? <a
|
|
|
|
|
class="hover:underline text-primary-700"
|
|
|
|
|
href="/signup{$page.url.search}">Sign up</a
|
|
|
|
|
>
|
2022-11-30 09:18:41 +01:00
|
|
|
{:else}
|
2023-09-14 06:42:16 +01:00
|
|
|
Already have an account? <a
|
|
|
|
|
class="hover:underline text-primary-700"
|
|
|
|
|
href="/login{$page.url.search}">Log In</a
|
2023-08-20 19:08:48 +00:00
|
|
|
>
|
2022-11-30 09:18:41 +01:00
|
|
|
{/if}
|
|
|
|
|
</div>
|
|
|
|
|
{/if}
|
2022-11-28 11:23:46 +01:00
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<style>
|
2023-08-18 19:28:41 +00:00
|
|
|
.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>
|