kingpeppe
04/09/2022, 10:24 PMsilentworks
04/09/2022, 10:35 PMkingpeppe
04/10/2022, 4:12 AMjs
import { createClient } from '@supabase/supabase-js';
const supabaseUrl = import.meta.env.VITE_PUBLIC_SUPABASE_URL;
const supabaseKey = import.meta.env.VITE_PUBLIC_SUPABASE_KEY;
export const supabase = createClient(supabaseUrl, supabaseKey);
data is then fed into tokens and partners stores like so
lib/stores/tokens.js
js
import { readable, get } from 'svelte/store';
import { supabase } from '$lib/supabase.js';
let initiated = false;
export const tokens = readable(null, (set) => {
if (!initiated) {
supabase
.from('tokens')
.select('*')
.then(({ error, data }) => set(data));
initiated = true;
}
const subscription = supabase
.from('tokens')
.on('*', (payload) => {
if (payload.eventType === 'INSERT') {
set([...get(tokens), payload.new]);
}
if (payload.eventType === 'DELETE') {
set([...get(tokens)].filter((token) => token.id != payload.old.id));
}
if (payload.eventType === 'UPDATE') {
const index = [...get(tokens)].findIndex((token) => token.id === payload.new.id);
let original = [...get(tokens)];
original[index] = payload.new;
set(original);
console.log('UPDATE TRIGGERED AND STORE SET');
}
})
.subscribe();
return () => supabase.removeSubscription(subscription);
});
to be used by pages and componentsFirefox can’t establish a connection to the server at wss://qwvcbjrghetgbxqowrqc.supabase.co/realtime/v1/websocket?blahblahblah
The connection to wss://qwvcbjrghetgbxqowrqc.supabase.co/realtime/v1/websocket?blahblahblah was interrupted while the page was loading.
It looks like these errors start to appear as soon as I enable the context module script in my __layout.svelte file. Its purpose is to not show the page until the data has loaded.
js
<script context="module">
import { tokens } from '$lib/stores/tokens';
export async function load() {
const data = await new Promise((resolve, reject) => {
let unsubscribe = () => {};
unsubscribe = tokens.subscribe((data) => {
if (!data) return;
unsubscribe();
resolve(data);
});
});
return {};
}
</script>
Any idea how to resolve this issue?