Bolt 应用中登录邮件的工作方式
Bolt 的内置数据库包含认证功能,项目有了数据库后就会出现相关设置:点击屏幕顶部的数据库图标,然后选择 Authentication。当有人注册、申请密码重置或魔法链接时,邮件由数据库的认证服务发送(Bolt 的文档说明其模板由 Supabase 提供支持),邮件中的链接根据你的 Site URL 和重定向列表生成。
Bolt 中的登录选项
| 登录方式 | 用户会收到的邮件 | 用 Proxy Mail QA 测试 |
|---|---|---|
| 邮箱和密码 | 确认(如果你要求)、密码重置、邮箱变更 | 是 |
| 魔法链接或验证码,如果你让 Bolt 添加 | 用于登录的链接或验证码 | 是 |
| 使用 Google 继续 | 登录时没有邮件 | 否:使用你自己的 Google 账号 |
Google 登录需要你自己的 Google Cloud OAuth 客户端:Bolt 会在 All project settings → Authentication → Continue with Google 下显示需要添加到那里的重定向地址。请在发布后的应用上测试,而不只是预览。不熟悉这些选项?请看 登录方式详解。
5 分钟测完每封登录邮件
- 开启确认。 点击数据库图标,然后选择 Authentication → Email,如果你的应用需要验证地址,就开启 Require users to confirm their email after signing up。
- 发布后,在 Proxy Mail QA 中创建地址;如果表单需要填写姓名,可使用生成的身份信息。
- 在发布后的应用上注册,而不只是在预览中。
- 使用行中的链接或验证码。 确认链接有 Open link 和 Copy link 按钮;验证码有 Copy 按钮。
- 然后测试其余部分: 退出登录、重置密码、用新密码登录,并将密码保存在该行上。还没有 Forgot password 链接?让 Bolt 添加一个。
需要检查的两项设置
1. Site URL 和重定向。 在 Advanced Authentication options 下,Site URL 应为你发布后的地址,URI allow list 应包含应用运行的每个地址。如果重置链接跳转到 localhost:3000,原因就在这里。Proxy Mail QA 会标记指向本地地址的链接,包括验证后才重定向到本地地址的链接。完整指南。
2. 邮件模板。 在 Authentication 中点击 Email 行,然后点击 Edit email templates,修改每封邮件的主题和正文。如果在模板中加入验证码({{ .Token }}),该行会显示验证码和 Copy 按钮;链接({{ .ConfirmationURL }})会有 Open link 和 Copy link 按钮。
适用于 Bolt 的可直接复制的提示词
将这些粘贴到 Bolt 的聊天中。然后用新地址再测试一次。
List every email this app sends: sign-up confirmation, magic link, password reset, invite and email change. For each, tell me what triggers it, which URL its link points to, and how long its link or code stays valid. Flag anything that uses localhost.Make every auth email link back to the published app, not localhost. Use the current site's address for the sign-up and password-reset redirects, and make sure the published address is in the authentication redirect list.After a password reset, send the user to a page where they choose a new password, then sign them in. Show a clear message if the reset link has expired or was already used.