Supabase Auth:Email 登录配置
1. 启用 Email
Email 登录默认已开启。
配置路径:Authentication → Sign In / Providers
默认安全策略:
- 不允许匿名登录
- 注册时必须进行邮箱验证
2. Supabase 配置自定义 SMTP
Supabase 默认提供内置的邮件发送服务,但它有极其严格的限制。每小时仅限 2 条 认证相关邮件, 所以建议配置自定义 SMTP 服务,我们这里选择Resend。
配置路径:Supabase Dashboard -> Authentication -> Email -> SMTP Settings -> Enable custom SMTP
1. 关于 Resend
Resend是最推荐的 OSS 服务,每月 3000 封免费额度,同时对 Next.js 支持极好,UI 现代,配置简单。
-
创建 API key
- 注册登录 resend
- 在Send your first email配置 API key 并测试邮件发送成功
-
配置自定义域名
- 使用子域名
notifications.xx.com - 如果域名在
cloudflare托管,点击跳转后会自动配置,等待配置完成及验证通过 - 如果是其他平台,也可以参考弹出的配置说明,自定义配置
- 使用子域名
-
获取 API key 和 SMTP 参数
- SMTP 参数位于 Send emails using SMTP instead of the REST API.
- 获取 API key
2. 在 Supabase 中使用 Resend 作为自定义邮件服务
填写以下配置:
-
Sender email address:
noreply@sample.com -
Sender name:自定义名称
-
SMTP 参数:
- Host:
smtp.resend.com - Port:
465 - Username:
resend - Password: Resend 的 API Key
- Host:
3. 自定义邮件模板
Supabase 支持自定义认证相关邮件内容(如注册验证、重置密码等)。
配置路径:Supabase Dashboard -> Authentication -> Email -> Templates