Richi
Richi

Reputation: 576

Can't add more than one field user_meta_data supabase

I am doing a user registration through nodejs, this was already done in react but only with one field. The problem is that I try to send more than one field in the metadata of the record but it only adds username to the profiles table and not the others. However I get user information on the front end and there is the additional metadata that was added.

I'm using supabase v2.0

const createStripeAccount = async(req, res) => {
  const { username, email, password } = req.body;
  try {
    const account = await stripe.accounts.create({
      type: 'express',
      country: 'US',
      email: email,
      capabilities: {
        card_payments: {requested: true},
        transfers: {requested: true},
      }
    });
    const { id:stripeAccountId } = account;
   
    let newData = null;
    if(stripeAccountId) {
      console.log(typeof stripeAccountId)
      newData = await supabase.auth.signUp(
        {
          email: email,
          password: password,
          options: {
            data: {
              username: username,
              stripe_account_user_id: 'stripeAccountId', <---additional
              is_founder: true, <---additional
              website: 'www.sdsoso.cl' <---additional
            }
          }
        }
      )
    }
    const { data: {user} } = newData;
    console.log(newData)
    return res.json({
      user
    });
    
  } catch(error) {
    console.log('error', error);
  }
}

The response from the server is the full metadata sended. But in the table only add username and not the others. enter image description here

enter image description here

Upvotes: 0

Views: 786

Answers (1)

Richi
Richi

Reputation: 576

I found the solution and it was that I had forgotten that when I add new metadata I must update the function that is fired in the supabase trigger after registering. So every time you want to pass more data to the profiles table after registration, update the function that is triggered. In my case:

BEGIN
  INSERT INTO public.profiles(id, username, new_col_name)
  VALUES (
    NEW.id,
    NEW.raw_user_meta_data -> 'username',
    NEW.raw_user_meta_data -> 'new_col_name'
  );
  RETURN NEW;
END;

Upvotes: 3

Related Questions