Hey guys, I'm using NextJS + Supabase, and am sett...
# help
r
Hey guys, I'm using NextJS + Supabase, and am setting up a CI/CD for the frontend with GH Actions. In my GH Action, I have a step where I
npm run build
the Next app before running
npm run test
. Problem: I get the error
Error: supabaseUrl is required
during the build step. This is happening because
createClient(process.env.NEXT_PUBLIC_SUPABASE_URL ?? '', process.env.SUPABASE_SERVICE_ROLE_KEY ?? '')
runs on the client-side and I haven't passed those 2 environment variables to the GH action. Solutions I'm looking at: a) Add prod DB environment variables to the GH action so
createClient()
doesn't throw an error. This feels too dangerous. b) Create a special 'test' environment and pass its env variables to the GH action. This sounds like a lot of work as I'll have to manually keep the test DB in sync with prod DB. c) Move
createClient()
onto server-side and expose the client instance as an API for my frontend to consume. This way,
npm run build
wouldn't need those ENV variables to build correctly. Is this even possible? Thoughts 🙂 ?
s
I just add my env variables to GitHub as this is the build process for my production app. If you are doing this purely for testing purpose then yes setup another project in Supabase and use the keys from that.
r
@User That sounds like an option, but the frontend and backend are really tightly coupled this way. The whole frontend basically fails to build if
createClient()
throws an error. Is it possible for
createClient()
to live server-side?
s
You can create two instances of that, I have one that solely works in the server-side since it contains the
service_role
key
https://github.com/silentworks/waiting-list/tree/main/src/lib I have one instance in
admin.js
and another in
db.js
r
Interesting - so I can completely avoid initialising the client on the frontend?
Taking a look at your branch but I'm not too familiar with svelte
s
So I'm making use of the code that uses the service_role key in this file https://github.com/silentworks/waiting-list/blob/main/src/routes/api/invite.json.js which is server-side only, while the client-side has no access to this instance of supabase.
r
Ahh I see - going to give it a bash tomorrow. Thanks!