auth icon indicating copy to clipboard operation
auth copied to clipboard

Internally inviteUserByEmail is not reading .data.custom_value when sending invitation email.

Open flesicek opened this issue 2 years ago • 3 comments

Bug report

  • [x] I confirm this is a bug with Supabase, not with my own application.
  • [x] I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

We have before insert trigger on top of the auth.users that is adding custom variables into raw_user_meta_data field. When the inviteUserByEmail function is triggered, Invite user email is sent, but {{ .Data.custom_variable }} is empty <- this is the bug

To Reproduce

Steps to reproduce the behavior, please provide code snippets or a repository:

  1. Create a before insert trigger on the auth.users table
  2. In the trigger function, set NEW.raw_user_meta_data['custom_variable'] = to_jsonb('Custom text'::text);
  3. In the Invite email template, add into body {{ .Data.custom_variable }}
  4. Trigger Supabase JS function inviteUserByEmail

Expected behavior

The invite email should have somewhere text "Custom text". But there will be nothing.

flesicek avatar Jan 08 '24 17:01 flesicek

hi @flesicek, you can insert custom user metadata by passing a data object in the options field when you can inviteUserByEmail if you use supabase-js like:

const { error } = await supabase.auth.admin.inviteUserByEmail({ 
  email, 
  options: { 
    data: { 
      custom_variable: 'xxx' 
    }
  }
})

we currently don't support fetching the user record from the db after creating it which is why the before insert trigger is not being reflected when the email is being sent out

kangmingtay avatar Feb 05 '24 15:02 kangmingtay

@kangmingtay the example above does not work and results in

error: AuthApiError: Could not parse request body as JSON: json: cannot unmarshal object into Go struct field .email of type string

i could only get this to work but options do not popular auth.users table

const resp = await supabase.auth.admin.inviteUserByEmail( "[email protected]", { data: { x: 1 }, } );

lanbau avatar Aug 12 '24 23:08 lanbau

@kangmingtay Any updates here? I think I am facing a similar issue. I am passing in metadata when calling the inviteUserByEmail function and only one of my key/value pairs is persisting in the data response and template (the name).

const { data, error } = await supabase.auth.admin.inviteUserByEmail(email, {
   data: {
      name,
      client_name,
      invite_token
   }
})

branmar97 avatar Oct 05 '24 06:10 branmar97