Skip to content

Commit c77ba90

Browse files
authored
Merge pull request #48 from dscsnu/SmallFix
Token FIx
2 parents a8c21ab + 42f0d81 commit c77ba90

File tree

2 files changed

+36
-30
lines changed

2 files changed

+36
-30
lines changed

frontend/src/routes/+layout.svelte

Lines changed: 36 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,73 @@
11
<script lang="ts">
2-
import '../app.css';
3-
import { onMount } from 'svelte';
4-
import { invalidateAll } from '$app/navigation';
5-
import { device, setDevice } from '$lib/stores/DeviceStore';
6-
import { SupaStore, UserStore } from '$lib/stores/SupabaseStore';
7-
import MobileOnly from '$lib/components/MobileOnly.svelte';
8-
import { PUBLIC_ENVIRONMENT } from '$env/static/public';
9-
import { setToken, token } from '$lib/stores/TokenStore';
10-
import { ToastStore } from '$lib/stores/ToastStore';
11-
import Toast from '$lib/components/Toast.svelte';
12-
import { LoadingStore } from '$lib/stores/LoadingStore';
13-
import Loading from '$lib/components/Loading.svelte';
2+
import "../app.css";
3+
import { onMount } from "svelte";
4+
import { invalidateAll } from "$app/navigation";
5+
import { device, setDevice } from "$lib/stores/DeviceStore";
6+
import { SupaStore, UserStore } from "$lib/stores/SupabaseStore";
7+
import MobileOnly from "$lib/components/MobileOnly.svelte";
8+
import { PUBLIC_ENVIRONMENT } from "$env/static/public";
9+
import { setToken } from "$lib/stores/TokenStore";
10+
import { ToastStore } from "$lib/stores/ToastStore";
11+
import Toast from "$lib/components/Toast.svelte";
12+
import { LoadingStore } from "$lib/stores/LoadingStore";
13+
import Loading from "$lib/components/Loading.svelte";
1414
1515
let { data, children } = $props();
1616
let { supabase, session, user } = $derived(data);
1717
1818
onMount(() => {
1919
const {
20-
data: { subscription }
20+
data: { subscription },
2121
} = supabase.auth.onAuthStateChange((event, newSession) => {
22-
if (newSession?.expires_at !== session?.expires_at || event === 'SIGNED_OUT') {
22+
if (
23+
newSession?.expires_at !== session?.expires_at ||
24+
event === "SIGNED_OUT"
25+
) {
2326
setToken(null);
2427
invalidateAll();
2528
}
2629
27-
if (['SIGNED_IN', 'TOKEN_REFRESHED'].includes(event) && session?.access_token) {
30+
if (
31+
["SIGNED_IN", "TOKEN_REFRESHED"].includes(event) &&
32+
session?.access_token
33+
) {
2834
setToken(session.access_token);
2935
}
3036
});
3137
3238
SupaStore.set(supabase);
3339
UserStore.set(user);
3440
35-
if (window.matchMedia('(max-width: 767px)').matches) setDevice('mobile');
36-
else setDevice('desktop');
41+
if (window.matchMedia("(max-width: 767px)").matches)
42+
setDevice("mobile");
43+
else setDevice("desktop");
3744
3845
return () => subscription.unsubscribe();
39-
})
46+
});
4047
</script>
4148

4249
<!-- handle device resize -->
43-
<svelte:window onresize={() => setDevice(window.matchMedia('(max-width: 767px').matches ? 'mobile' : 'desktop')}/>
50+
<svelte:window
51+
onresize={() =>
52+
setDevice(
53+
window.matchMedia("(max-width: 767px").matches
54+
? "mobile"
55+
: "desktop",
56+
)}
57+
/>
4458

45-
{#if $device === 'mobile' || PUBLIC_ENVIRONMENT === 'development'}
59+
{#if $device === "mobile" || PUBLIC_ENVIRONMENT === "development"}
4660
{@render children()}
4761
{:else}
4862
<MobileOnly />
4963
{/if}
5064

5165
{#if $ToastStore}
5266
{#each $ToastStore as toast (toast.id)}
53-
<Toast {...toast}/>
67+
<Toast {...toast} />
5468
{/each}
5569
{/if}
5670

5771
{#if $LoadingStore}
5872
<Loading />
59-
{/if}
73+
{/if}

frontend/src/routes/+page.svelte

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
<script lang="ts">
2-
import { onMount } from 'svelte';
3-
import { token } from '$lib/stores/TokenStore';
4-
import { goto } from '$app/navigation';
52
let { data } = $props();
63
let { supabase, user } = $derived(data);
74
@@ -17,11 +14,6 @@
1714
}
1815
})
1916
}
20-
onMount(() => {
21-
if (token) {
22-
goto('/newplayer');
23-
}
24-
});
2517
</script>
2618

2719
<main class={`h-screen w-screen flex flex-col justify-center items-center`}>

0 commit comments

Comments
 (0)