stewiethepro
07/22/2022, 4:31 AMconst 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
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:
// 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?Needle
07/22/2022, 4:31 AMsilentworks
07/22/2022, 12:45 PMsupabase.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.stewiethepro
07/22/2022, 11:23 PMsilentworks
07/22/2022, 11:55 PM