I am using Nextjs and I am trying to hit the supab...
# javascript
k
I am using Nextjs and I am trying to hit the supabase auth endpoint by calling the function
Copy code
const { user, session, error } = await supabase.auth.signUp({
  email: 'example@email.com',
  password: 'example-password',
})
I have set the anon and supabase url and it works because I can hit the regular rest api. When I use the the auth function, it calls the wrong endpoint.
Copy code
http://localhost:3000/undefined/auth/v1/signup
It should be calling the supabase url and instead of
Copy code
http://locahost:3000/undefined
I have found the error but I do not know how to fix it.
Copy code
import { createClient } from '@supabase/supabase-js'

let supabaseUrl = process.env.SUPABASE_URL
let supabaseAnonKey = process.env.SUPABASE_ANON_KEY

export const supabase = createClient(supabaseUrl, supabaseAnonKey)
Because this is typescript,
supabaseUrl
and
supabaseeAnonKey
are type
string | undefined
and they default to undefined at the start
g
You probably need to use NEXT_PUBLIC_ at start of env vars for the browser. https://github.com/supabase/supabase/discussions/3218#discussioncomment-2021448
k
Thank you for that! I also found out that you can get it to work by adding it to the next.config.js. Took me wayyyyy too long to get this figured out lol.