Customizing Emails by Language
当你注册一个用户时,你可以创建关于他们的元数据。
🌐 When you register a user, you can create meta-data about them.
使用 JS-Client 的 signUp 函数 创建元数据
🌐 Creating meta-data with the JS-Client's signUp function
1const { data, error } = await supabase.auth.signUp({2 email: 'email@some_[email.com](http://email.com/)',3 password: 'example-password',4 options: {5 data: {6 first_name: 'John',7 last_name: 'Doe',8 age: 27,9 },10 },11})上面的例子创建了一个用户条目,其中包括他们的名称和年龄信息。数据存储在 auth.users 表的 auth.raw_user_meta_data 列中。你可以使用 SQL 编辑器 在 auth 模式中查看它。
🌐 The above example creates a user entry that includes information about their name and age. The data is stored in the auth.users table in the auth.raw_user_meta_data column. You can view it in the auth schema with the SQL Editor.
可以在项目的电子邮件模板中访问。下面是一个示例:
🌐 It can be accessed in a project's Email Templates. Below is an example:
1<h2>Hello, {{ .Data.first_name }} {{ .Data.last_name }}!</h2>23<p>Follow this link to confirm your account:</p>4<p><a href="{{ .ConfirmationURL }}">Confirm your account</a></p>如果你需要更新用户的元数据,你可以使用 updateUser 函数来完成。
🌐 If you need to update a user's meta-data, you can do so with the updateUser function.
元数据可以用来存储用户的语言偏好。然后你可以在邮件模板中使用“if语句”来为特定语言设置回复:
🌐 The meta-data can be used to store a user's language preferences. You could then use "if statements" in the email template to set the response for a specific language:
1{{if eq .Data.language "en" }}2<h1>Welcome!</h1>3{{ else if eq .Data.language "pl" }}4<h1>Witamy!</h1>5{{ else }}6<h1>chuS'ugh, tera' je (Klingon)</h1>7{{end}}Supabase 使用 Go 模板语言 来渲染邮件。它有一些高级条件功能,你可能想要去 了解一下。更多例子可以参考一个 GitHub 讨论,里面讲了高级语言模板。
🌐 Supabase uses the Go Templating Language to render emails. It has advanced features for conditions that you may want to explore. For more examples, there is a GitHub discussion that discusses advanced language templates.