-
Notifications
You must be signed in to change notification settings - Fork 230
/
Copy path+page.svelte
55 lines (49 loc) · 1.41 KB
/
+page.svelte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<script lang="ts">
import { onMount } from 'svelte';
import { supabaseClient } from '$lib/db';
import { page } from '$app/stores';
let auth: typeof import('supabase-ui-svelte').default;
onMount(async () => {
const { default: Auth } = await import('supabase-ui-svelte');
auth = Auth;
});
let loadedData: any[] = [];
async function loadData() {
const { data } = await supabaseClient.from('test').select('*').single();
loadedData = data;
}
$: if ($page.data.session.user) {
loadData();
}
</script>
<h1>Welcome to SvelteKit</h1>
<p>Visit <a href="https://kit.svelte.dev">kit.svelte.dev</a> to read the documentation</p>
{#if !$page.data.session.user}
<button
on:click={() => {
supabaseClient.auth.signIn({ provider: 'github' }, { scopes: 'public_repo user:email' });
}}
>
GitHub with scopes
</button>
<svelte:component
this={auth}
{supabaseClient}
providers={['google', 'github']}
socialLayout="horizontal"
socialButtonSize="large"
/>
{:else}
<p>
[<a href="/profile">withPageAuth</a>] | [<a href="/protected-page">supabaseServerClient</a>] | [<a
href="/github-provider-token">GitHub Token</a
>] |
<button on:click={() => supabaseClient.auth.update({ data: { test5: 'updated' } })}>
Update
</button>
</p>
<p>user:</p>
<pre>{JSON.stringify($page.data.session.user, null, 2)}</pre>
<p>client-side data fetching with RLS</p>
<pre>{JSON.stringify(loadedData, null, 2)}</pre>
{/if}