https://supabase.com/ logo
#help
Title
# help
m

Michie

02/16/2022, 12:10 PM
I'm have having issues with Supabase if I am using 2 projects in one app. No issues at local but if deployed via Vercel or Heroku, it has an
error: supabaseURL is required.
Any idea why this is happening when deployed? Thx
s

silentworks

02/16/2022, 1:51 PM
You are missing an env variable or your env variables aren't being set properly
m

Michie

02/16/2022, 7:12 PM
hi silentworks, nope. I have set all the variables both in vercel and heroku and they are having the same errors. I have checked on this many times and this only happens during deployment but working fine on local.
s

silentworks

02/16/2022, 7:13 PM
The error is saying the env variable is not being set properly or is missing
create a console.log in your code where you instantiate the supabaseClient library to make sure there is a value there
m

Michie

02/16/2022, 7:17 PM
I also even tried putting the env variable on the actual code instead of the env setting and deployed it and still I have the same error.
Btw, I created 2 js file to instantiate supabase - and both of them have different file name and use different env keys.
I don't know if that's the cause of the conflict when deployed?
s

silentworks

02/16/2022, 7:19 PM
That shouldn't make a difference if the variables are set
I have 2 files in my project too, albeit using the same url but one is using the service_key while the other is using the anon_key
can you share the code snippet where you are instantiating the
createClient
supabase code please?
m

Michie

02/16/2022, 7:26 PM
Here's the keys that I have setup at vercel and same with heroku. 🙂
s

silentworks

02/16/2022, 7:26 PM
Ok, but I was after the
js
code
m

Michie

02/16/2022, 7:28 PM
Here's the code: supabase.js
Copy code
import { createClient } from '@supabase/supabase-js'

const supabaseUrl = process.env.SUPABASE_URL
const supabaseKey = process.env.SUPABASE_KEY
const supabase = createClient(supabaseUrl, supabaseKey)

export default supabase
supabase-admin.js
Copy code
import { createClient } from '@supabase/supabase-js'

const supabaseUrlAdmin = process.env.SUPABASE_URL_ADMIN
const supabaseKeyAdmin = process.env.SUPABASE_KEY_ADMIN
const supabaseAdmin = createClient(supabaseUrlAdmin, supabaseKeyAdmin)

export default supabaseAdmin
s

silentworks

02/16/2022, 7:31 PM
What version of nuxt are you using?
m

Michie

02/16/2022, 7:32 PM
"nuxt": "^2.14.6"
s

silentworks

02/16/2022, 7:36 PM
If you do a console.log('URL: ', process.env.SUPABASE_URL) inside of your
supabase.js
file then do a heroku or netlify build with it, what happens?
m

Michie

02/16/2022, 7:36 PM
ok for a while I will do that 🙂
Here's the result
s

silentworks

02/16/2022, 7:47 PM
Is your URL missing a https://?
Sorry you blocked out part which I would think is the project reference id
ah ok
This is just weird to me, because the URL is there.
Do you get this same error even when you hardcode the URL into the
createClient
code?
m

Michie

02/16/2022, 7:51 PM
Yes!!!!
I don't know if there is conflict having two supabase client when deployed 🤔
So I don't think that would be an issue
Can you have a look at this blog post and see if changing to use this setup helps https://nuxtjs.org/tutorials/moving-from-nuxtjs-dotenv-to-runtime-config/
m

Michie

02/16/2022, 8:12 PM
@User it's working now. Thank you so much for the help. 🙏 I do have a question, is it safe to store the service_role keys at the vercel environment setting? I have read in their documentation that: The value is encrypted at rest so it is safe to add sensitive data like authentication tokens or private keys. But still have doubts because if the service_role key is exposed, anyone can have accessed to it.
s

silentworks

02/16/2022, 8:13 PM
As long as its only available to the server side part of your code then its fine
I don't know how NUXT deals with env variables but using Vite with SvelteKit, the only env variable that is exposed to the client side are those that start with
VITE_
m

Michie

02/16/2022, 8:15 PM
Thank you! I will read more about this and thank you again for the help! 🙂
s

silentworks

02/16/2022, 8:19 PM
No problem, I'm happy you got it resolved.