跳到主要内容
版本:Current

认证配置

实现:auth.ts、lib/user-login-gate.ts。

流程​

Google 客户端​

  • 授权参数:prompt=select_account,避免浏览器沿用上一个账号。
  • allowDangerousEmailAccountLinking: true:库中已有同邮箱用户但还没有 Google accounts 行时,允许挂上 OAuth,避免 OAuthAccountNotLinked。
  • Session 策略:JWT(不是 database session 作为主策略)。

登录门禁​

  • 无邮箱 → 拒绝。
  • users 为空:仅当 AUTH_ALLOW_EMPTY_USER_TABLE 为 1/true 才允许。
  • users 非空:lower(trim(email)) 必须命中一行。
  • 若 public.users 表不存在(Postgres 42P01),当前代码允许登录并打日志,应视为配置错误。

角色注入​

JWT 回调按 users.id 读 role,缺省 'voter'。改角色后用户需重新登录,侧栏和 Action 才会拿到新 role。