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

130 lines
4.0 KiB
Svelte
Raw Normal View History

<script lang="ts">
2025-11-01 15:49:29 +01:00
import { preventDefault } from '$lib/utils/functions/svelte';
import { page } from '$app/state';
2023-08-17 14:05:01 +01:00
import Avatar from '$lib/components/Avatar/index.svelte';
import { VARIANTS } from '$lib/components/PrimaryButton/constants';
import PrimaryButton from '$lib/components/PrimaryButton/index.svelte';
import { t } from '$lib/utils/functions/translations';
2023-08-17 14:05:01 +01:00
import { currentOrg } from '$lib/utils/store/org';
import type { SupabaseClient } from '@supabase/supabase-js';
import GoogleIconColored from '../Icons/GoogleIconColored.svelte';
2022-11-28 11:23:46 +01:00
2025-11-01 15:49:29 +01:00
interface Props {
supabase: SupabaseClient;
handleSubmit?: any;
isLogin?: boolean;
showOnlyContent?: boolean;
isLoading?: boolean;
showLogo?: boolean;
formRef: any;
hideGoogleAuth?: boolean;
redirectPathname?: string;
children?: import('svelte').Snippet;
}
let {
supabase,
handleSubmit = () => {},
isLogin = true,
showOnlyContent = false,
isLoading = false,
showLogo = false,
formRef = $bindable(),
hideGoogleAuth = false,
redirectPathname = '',
children
}: Props = $props();
2022-11-28 11:23:46 +01:00
async function signInWithGoogle() {
2023-08-04 12:49:34 +01:00
if (isLoading) {
return;
}
2023-12-14 11:44:49 +03:00
const params = new URLSearchParams(window.location.search);
console.log({ params });
// const redirectTo = `https://app.classroomio.com?forwardTo=${
// window.location.origin + params.get('redirect')
// }`;
const pathname = redirectPathname || params.get('redirect');
const redirectTo = `${window.location.origin + pathname}`;
2023-12-14 11:44:49 +03:00
console.log({ redirectTo });
2022-12-03 22:45:01 +01:00
try {
console.log('signInWithGoogle');
const { error, data } = await supabase.auth.signInWithOAuth({
2023-12-14 11:44:49 +03:00
provider: 'google',
options: {
redirectTo
}
2022-12-03 22:45:01 +01:00
});
console.log('data', data);
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="app-background flex min-h-screen w-full items-center justify-center">
<div class="border-gray container border bg-white dark:bg-black">
<div class="flex flex-col items-center p-2 lg:px-8 lg:py-3">
2022-12-03 22:45:01 +01:00
{#if !showOnlyContent || showLogo}
<div class="flex w-full flex-col items-center justify-center 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"
2024-04-22 18:25:14 +01:00
height="max-h-10"
2023-08-18 08:28:18 +01:00
className="mr-2"
2023-08-17 14:05:01 +01:00
/>
2023-12-05 08:31:26 +03:00
<a href="/">
<h4 class="mt-0 text-xl dark:text-white">
2023-12-05 08:31:26 +03:00
{$currentOrg.name ? $currentOrg.name : 'ClassroomIO'}
</h4>
</a>
2022-11-30 09:18:41 +01:00
</div>
{/if}
2025-11-01 15:49:29 +01:00
<form bind:this={formRef} onsubmit={preventDefault(handleSubmit)} class="flex w-10/12 flex-col items-center">
{@render children?.()}
2022-11-28 11:23:46 +01:00
</form>
{#if !showOnlyContent && !hideGoogleAuth}
<div class="mb-3 w-10/12">
<p class="mb-5 text-sm dark:text-white">{$t('login.signup_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 />
<span class="ml-2">
{isLogin ? $t('login.login_with_google') : $t('login.signup_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="border-grey w-full border-t p-6 text-center">
2022-11-30 09:18:41 +01:00
{#if isLogin}
{$t('login.not_registered_yet')}
2025-11-01 15:49:29 +01:00
<a class="text-primary-700 hover:underline" href="/signup{page.url.search}">{$t('login.signup')}</a>
2022-11-30 09:18:41 +01:00
{:else}
{$t('login.already_have_account')}
2025-11-01 15:49:29 +01:00
<a class="text-primary-700 hover:underline" href="/login{page.url.search}">{$t('login.login')}</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>