From ff445f278cf4eac4ff7ca8b25a6e165822f96f96 Mon Sep 17 00:00:00 2001 From: wipdev-tech Date: Sat, 14 Oct 2023 01:27:28 +0300 Subject: [PATCH 1/2] feat: bypass supabase via env variable --- README.md | 11 +++++++++++ src/lib/helpers/supabase.ts | 4 ++-- src/lib/stores/authStore.ts | 14 +++++++++----- 3 files changed, 22 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index bf628bc..da415c6 100644 --- a/README.md +++ b/README.md @@ -1 +1,12 @@ # learnbuildteach.com + +## Contribution + +### Bypassing Supabase + +The production website fetches data from [Supabase](https://supabase.com/). To +bypass this, set the following variable in your `.env` file: + +``` +PUBLIC_BYPASS_SUPABASE=true +``` 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(); From f95f5b198da5b49b0b5358e4f485a0d710b1d794 Mon Sep 17 00:00:00 2001 From: wipdev-tech Date: Sat, 14 Oct 2023 01:38:58 +0300 Subject: [PATCH 2/2] fix(readme): clearer text for bypassing supabase --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index da415c6..82ec6b4 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,12 @@ ### Bypassing Supabase -The production website fetches data from [Supabase](https://supabase.com/). To -bypass this, set the following variable in your `.env` file: +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.