mirror of
https://github.com/jcreek/SvelteKitSaasBoilerplate.git
synced 2026-07-13 02:53:50 +00:00
feat(#60): Clear basket on sign out
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { createEventDispatcher } from 'svelte';
|
import { createEventDispatcher } from 'svelte';
|
||||||
|
import { basket, type Basket, type Item } from '$lib/stores/basket.js';
|
||||||
|
|
||||||
const dispatch = createEventDispatcher();
|
const dispatch = createEventDispatcher();
|
||||||
|
|
||||||
function emitSignedOutEvent() {
|
function emitSignedOutEvent() {
|
||||||
@@ -9,10 +11,23 @@
|
|||||||
// Access the supabase client from the layout data
|
// Access the supabase client from the layout data
|
||||||
export let supabase: any;
|
export let supabase: any;
|
||||||
|
|
||||||
|
let localBasket: Basket;
|
||||||
|
const unsubscribe = basket.subscribe((value) => {
|
||||||
|
localBasket = value;
|
||||||
|
});
|
||||||
|
|
||||||
async function signOut() {
|
async function signOut() {
|
||||||
// TODO use the error from the response
|
// TODO use the error from the response
|
||||||
const { error } = await supabase.auth.signOut().then(() => {
|
const { error } = await supabase.auth.signOut().then(() => {
|
||||||
emitSignedOutEvent();
|
emitSignedOutEvent();
|
||||||
|
|
||||||
|
// Clear the basket
|
||||||
|
localBasket = { items: [], subtotal: 0 };
|
||||||
|
basket.set(localBasket);
|
||||||
|
unsubscribe();
|
||||||
|
if (typeof localStorage !== 'undefined') {
|
||||||
|
localStorage.removeItem('basket');
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in New Issue
Block a user