Skip to content

Commit

Permalink
Move to onDestroy
Browse files Browse the repository at this point in the history
  • Loading branch information
evlim authored Nov 2, 2024
1 parent 48ca9a6 commit d83e5de
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/routes/(admin)/account/+layout.svelte
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
<script lang="ts">
import { run } from "svelte/legacy"
import { invalidate } from "$app/navigation"
import { onMount } from "svelte"
import { onMount, onDestroy } from "svelte"
let { data, children } = $props()
let { supabase, session } = $state(data)
run(() => {
;({ supabase, session } = data)
})
onMount(() => {
const { data } = supabase.auth.onAuthStateChange((event, _session) => {
if (_session?.expires_at !== session?.expires_at) {
invalidate("supabase:auth")
}
})
;({ supabase, session } = data)
const { data: authData } = supabase.auth.onAuthStateChange(
(event, _session) => {
if (_session?.expires_at !== session?.expires_at) {
invalidate("supabase:auth")
}
},
)
return () => data.subscription.unsubscribe()
onDestroy(() => {
authData.subscription.unsubscribe()
})
})
</script>

Expand Down

0 comments on commit d83e5de

Please sign in to comment.