Skip to content

bypass supabase via env variable #33

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
4 changes: 2 additions & 2 deletions src/lib/helpers/supabase.ts
Original file line number Diff line number Diff line change
@@ -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);
14 changes: 9 additions & 5 deletions src/lib/stores/authStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();