认证配置
实现:auth.ts、lib/user-login-gate.ts。
流程
Google 客户端
- 授权参数:
prompt=select_account,避免浏览器沿用上一个账号。 allowDangerousEmailAccountLinking: true:库中已有同邮箱用户但还没有 Googleaccounts行时,允许挂上 OAuth,避免OAuthAccountNotLinked。- Session 策略:JWT(不是 database session 作为主策略)。
登录门禁
- 无邮箱 → 拒绝。
users为空:仅当AUTH_ALLOW_EMPTY_USER_TABLE为1/true才允许。users非空:lower(trim(email))必须命中一行。- 若
public.users表不存在(Postgres42P01),当前代码允许登录并打日志,应视为配置错误。
角色注入
JWT 回调按 users.id 读 role,缺省 'voter'。改角色后用户需重新登录,侧栏和 Action 才会拿到新 role。