Skip to content

Commit 80f58a7

Browse files
changes for supabase
1 parent 4ae8a95 commit 80f58a7

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
.env.development.local
1515
.env.test.local
1616
.env.production.local
17+
.env
1718

1819
npm-debug.log*
1920
yarn-debug.log*

docusaurus.config.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,4 +90,8 @@ module.exports = {
9090
}),
9191
],
9292
],
93+
customFields: {
94+
supabaseUrl: process.env.NEXT_PUBLIC_SUPABASE_URL,
95+
supabaseAnonKey: process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY,
96+
},
9397
}

src/pages/index.js

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,15 @@ const TechBackground = () => (
4444
</div>
4545
);
4646

47-
// Initialize Supabase client (add these environment variables to your .env)
48-
const supabase = createClient(
49-
process.env.NEXT_PUBLIC_SUPABASE_URL,
50-
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
51-
)
47+
// Move the client initialization inside a function
48+
const getSupabaseClient = () => {
49+
if (typeof window === 'undefined') return null; // Return null during SSR/build
50+
51+
return createClient(
52+
process.env.NEXT_PUBLIC_SUPABASE_URL,
53+
process.env.NEXT_PUBLIC_SUPABASE_ANON_KEY
54+
);
55+
};
5256

5357
export default function Home() {
5458
const { siteConfig } = useDocusaurusContext();
@@ -60,9 +64,14 @@ export default function Home() {
6064
setStatus('sending');
6165

6266
try {
67+
const supabase = getSupabaseClient();
68+
if (!supabase) {
69+
throw new Error('Supabase client not initialized');
70+
}
71+
6372
const { error } = await supabase
6473
.from('subscribers')
65-
.insert([{ email: email }])
74+
.insert([{ email: email }]);
6675

6776
if (error) throw error;
6877

0 commit comments

Comments
 (0)