https://supabase.com/ logo
Hey guys! I'm trying to post some form data to Su...
# help
s
Hey guys! I'm trying to post some form data to Supabase in an async function.
Copy code
const makeRequest = async (formData, userId) => {
  const supabase = getSupabase(userId)
  const { data: users, error } = await supabase
    .from("users")
    .update({ 
      user_type: formData.userType,
      first_name: formData.firstName,
      last_name: formData.lastName,
      is_onboarding: false 
    })
    .eq('user_id', userId)

    error ? console.log("Supabase error:", error) : console.log(data);
  }
But I'm getting this error: secretOrPrivateKey must have a value utils/supabase.js (18:20) @ supabase.auth.session
Copy code
16 | 
  17 |     supabase.auth.session = () => ({
> 18 |       access_token: jwt.sign(payload,  process.env.SUPABASE_SIGNING_SECRET),
     |                    ^
  19 |     })
  20 |   }
Here's where I'm signing the JWT:
Copy code
// utils/supabase.js
import { createClient } from '@supabase/supabase-js'
import jwt from 'jsonwebtoken'

const getSupabase = (userId) => {
  const supabase = createClient(
    process.env.NEXT_PUBLIC_SUPABASE_URL,
    process.env.NEXT_PUBLIC_SUPABASE_KEY
  )

  if (userId) {
    const payload = {
      userId,
      exp: Math.floor(Date.now() / 1000) + 60 * 60,
    }

    supabase.auth.session = () => ({
      access_token: jwt.sign(payload,  process.env.SUPABASE_SIGNING_SECRET),
    })
  }

  return supabase
}
I have my SUPABASE_SIGNING_SECRET in my .env.local file in the root directory. I'm signed in and retrieving a user id from the session, but when I submit the form it throws this error. Anyone able to point me in the right direction?
n
Hello @stewiethepro! This thread has been automatically created from your message in #843999948717555735 a few seconds ago. We have already mentioned the @User so that they can see your message and help you as soon as possible! Want to unsubscribe from this thread? Right-click the thread in Discord (or use the ``...`` menu) and select "Leave Thread" to unsubscribe from future updates. Want to change the title? Use the ``/title`` command! We have solved your problem? Click the button below to archive it.
s
You don't need to monkey patch the
supabase.auth.session
function, in this case you don't need to even be signing your jwt itself, I'm not sure why you have all that in your code, you just need to return the supabase const you created from the getSupabase function, it doesn't require anything else.
s
Thanks for the reply! Im using stytch for Auth and followed the supabase docs - https://supabase.com/docs/guides/integrations/stytch . They suggested packaging their user_id up with a JWT and signing it with the supabase secret to to validate it hasn’t been tampered with in transit
s
I have no idea why they need to monkey patch that method, but I can't find the error you are getting anywhere in the supabase-js, gotrue-js codebase