I'm have having issues with Supabase if I am using...
# help
m
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
You are missing an env variable or your env variables aren't being set properly
m
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
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
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
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
Here's the keys that I have setup at vercel and same with heroku. 🙂
s
Ok, but I was after the
js
code
m
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
What version of nuxt are you using?
m
"nuxt": "^2.14.6"
s
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
ok for a while I will do that 🙂
Here's the result
s
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
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
@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
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
Thank you! I will read more about this and thank you again for the help! 🙂
s
No problem, I'm happy you got it resolved.