diff --git a/README.md b/README.md index bf628bc..82ec6b4 100644 --- a/README.md +++ b/README.md @@ -1 +1,15 @@ # learnbuildteach.com + +## Contribution + +### Bypassing Supabase + +The production website fetches data from a [Supabase](https://supabase.com/) +instance. To bypass this, set the following variable in your `.env` file: + +``` +PUBLIC_BYPASS_SUPABASE=true +``` + +This should allow you to run the static parts of the website without server +errors. diff --git a/src/lib/helpers/supabase.ts b/src/lib/helpers/supabase.ts index 30a6d12..2e49630 100644 --- a/src/lib/helpers/supabase.ts +++ b/src/lib/helpers/supabase.ts @@ -1,4 +1,4 @@ import { createClient } from '@supabase/supabase-js'; -import { PUBLIC_SUPABASE_PROJECT_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public'; +import { PUBLIC_BYPASS_SUPABASE, PUBLIC_SUPABASE_PROJECT_URL, PUBLIC_SUPABASE_ANON_KEY } from '$env/static/public'; -export const supabase = createClient(PUBLIC_SUPABASE_PROJECT_URL, PUBLIC_SUPABASE_ANON_KEY); +export const supabase = PUBLIC_BYPASS_SUPABASE === "true" ? null : createClient(PUBLIC_SUPABASE_PROJECT_URL, PUBLIC_SUPABASE_ANON_KEY); diff --git a/src/lib/stores/authStore.ts b/src/lib/stores/authStore.ts index 6605dd2..2467ef3 100644 --- a/src/lib/stores/authStore.ts +++ b/src/lib/stores/authStore.ts @@ -3,13 +3,17 @@ import { writable } from 'svelte/store'; export const loggedIn = writable(false); -supabase.auth.onAuthStateChange((event, session) => { - loggedIn.set(!!session); -}); +if (supabase) { + supabase.auth.onAuthStateChange((event, session) => { + loggedIn.set(!!session); + }); +} const updateLoggedIn = async () => { - const { data } = await supabase.auth.getSession(); - loggedIn.set(!!data?.session); + if (supabase) { + const { data } = await supabase.auth.getSession(); + loggedIn.set(!!data?.session); + } }; updateLoggedIn();