Internally inviteUserByEmail is not reading .data.custom_value when sending invitation email.
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:
- Create a before insert trigger on the auth.users table
- In the trigger function, set
NEW.raw_user_meta_data['custom_variable'] = to_jsonb('Custom text'::text); - In the Invite email template, add into body {{ .Data.custom_variable }}
- Trigger Supabase JS function inviteUserByEmail
Expected behavior
The invite email should have somewhere text "Custom text". But there will be nothing.
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 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 }, } );
@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
}
})