Skip to content

Commit 52e668c

Browse files
kiwicoppleclaude
andcommitted
Revert environment variable handling - SUPABASE_SERVICE_ROLE_KEY should always be provided
This reverts commit 985e49f. The SUPABASE_SERVICE_ROLE_KEY environment variable should be properly configured in all build environments rather than being handled as optional. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent 985e49f commit 52e668c

File tree

2 files changed

+28
-52
lines changed

2 files changed

+28
-52
lines changed

website/data/static-path-queries.ts

Lines changed: 23 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,35 @@
1-
import supabaseAdmin, { isAdminAvailable } from '~/lib/supabase-admin'
1+
import supabaseAdmin from '~/lib/supabase-admin'
22

33
// [Alaister]: These functions are to be called server side only
44
// as they bypass RLS. They will not work client side.
55

66
export async function getAllProfiles() {
7-
// During build time, if admin client isn't available, return empty array
8-
if (!isAdminAvailable()) {
9-
console.warn('SUPABASE_SERVICE_ROLE_KEY not available during build - skipping profile paths generation')
10-
return []
11-
}
12-
13-
try {
14-
const [{ data: organizations }, { data: accounts }] = await Promise.all([
15-
supabaseAdmin
16-
.from('organizations')
17-
.select('handle')
18-
.order('created_at', { ascending: false })
19-
.limit(500)
20-
.returns<{ handle: string }[]>(),
21-
supabaseAdmin
22-
.from('accounts')
23-
.select('handle')
24-
.order('created_at', { ascending: false })
25-
.limit(500)
26-
.returns<{ handle: string }[]>(),
27-
])
7+
const [{ data: organizations }, { data: accounts }] = await Promise.all([
8+
supabaseAdmin
9+
.from('organizations')
10+
.select('handle')
11+
.order('created_at', { ascending: false })
12+
.limit(500)
13+
.returns<{ handle: string }[]>(),
14+
supabaseAdmin
15+
.from('accounts')
16+
.select('handle')
17+
.order('created_at', { ascending: false })
18+
.limit(500)
19+
.returns<{ handle: string }[]>(),
20+
])
2821

29-
return [...(organizations ?? []), ...(accounts ?? [])]
30-
} catch (error) {
31-
console.error('Error fetching profiles for static paths:', error)
32-
return []
33-
}
22+
return [...(organizations ?? []), ...(accounts ?? [])]
3423
}
3524

3625
export async function getAllPackages() {
37-
// During build time, if admin client isn't available, return empty array
38-
if (!isAdminAvailable()) {
39-
console.warn('SUPABASE_SERVICE_ROLE_KEY not available during build - skipping package paths generation')
40-
return []
41-
}
26+
const { data } = await supabaseAdmin
4227

43-
try {
44-
const { data } = await supabaseAdmin
45-
.from('packages')
46-
.select('handle,partial_name')
47-
.order('created_at', { ascending: false })
48-
.limit(1000)
49-
.returns<{ handle: string; partial_name: string }[]>()
28+
.from('packages')
29+
.select('handle,partial_name')
30+
.order('created_at', { ascending: false })
31+
.limit(1000)
32+
.returns<{ handle: string; partial_name: string }[]>()
5033

51-
return data ?? []
52-
} catch (error) {
53-
console.error('Error fetching packages for static paths:', error)
54-
return []
55-
}
34+
return data ?? []
5635
}

website/lib/supabase-admin.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,13 @@ if (!process.env.NEXT_PUBLIC_SUPABASE_URL) {
55
throw new Error('Missing NEXT_PUBLIC_SUPABASE_URL environment variable')
66
}
77

8-
// During build time, we might not have the service role key
9-
// In that case, we'll create a client that will be used later at runtime
8+
if (!process.env.SUPABASE_SERVICE_ROLE_KEY) {
9+
throw new Error('Missing SUPABASE_SERVICE_ROLE_KEY environment variable')
10+
}
11+
1012
const supabaseAdmin = createClient<Database>(
1113
process.env.NEXT_PUBLIC_SUPABASE_URL,
12-
process.env.SUPABASE_SERVICE_ROLE_KEY || 'dummy-key-for-build'
14+
process.env.SUPABASE_SERVICE_ROLE_KEY
1315
)
1416

15-
// Helper function to check if admin operations are available
16-
export const isAdminAvailable = () => {
17-
return !!process.env.SUPABASE_SERVICE_ROLE_KEY
18-
}
19-
2017
export default supabaseAdmin

0 commit comments

Comments
 (0)