hermes/hermes-996d586b #9

Merged
kdletters merged 8 commits from hermes/hermes-996d586b into master 2026-05-08 14:46:57 +08:00
2 changed files with 12 additions and 3 deletions
Showing only changes of commit 91d993dc6b - Show all commits

View File

@@ -20,11 +20,12 @@
- 重置密码后自动登录:`POST /api/auth/password/reset`
- 微信 OAuth callback 登录:`GET /api/auth/wechat/callback`
- 微信绑定手机号后激活/登录态刷新:`POST /api/auth/wechat/bind-phone`
- refresh cookie 续期:`POST /api/auth/session/refresh`
## 设计约束
1. 埋点写入不能阻断登录成功响应。
2. 只有认证成功并已创建会话后才记录。
2. 只有认证成功并已创建会话后,或 refresh session rotate 成功并签发新 access token 后才记录。
3. 失败只记 warning继续返回 token / cookie。
4. 写入统一收口,避免多个登录 handler 各自拼 procedure 调用。
5. 不修改 SpacetimeDB 表结构,不需要更新 `migration.rs`
@@ -48,7 +49,7 @@ record_daily_login_tracking_event_after_auth_success(
- 成功时记录 info
- 失败时记录 warn并明确“登录流程继续”
在各登录入口 `create_auth_session` 成功后调用该 helper。
在各登录入口 `create_auth_session` 成功后调用该 helper。refresh cookie 续期在 `rotate_session``sign_access_token_for_user` 成功后调用同一个 helper`login_method` 使用 refresh session 上保存的 `issued_by_provider`,避免把续期统一误标成 password。
## 验收

View File

@@ -13,7 +13,8 @@ use crate::{
auth::RefreshSessionToken,
auth_session::{
attach_set_cookie_header, build_clear_refresh_session_cookie_header,
build_refresh_session_cookie_header, map_refresh_session_error, sign_access_token_for_user,
build_refresh_session_cookie_header, map_refresh_session_error,
record_daily_login_tracking_event_after_auth_success, sign_access_token_for_user,
},
http_error::AppError,
request_context::RequestContext,
@@ -54,6 +55,13 @@ pub async fn refresh_session(
&rotated.session.session_id,
Some(&rotated.session.issued_by_provider),
)?;
record_daily_login_tracking_event_after_auth_success(
&state,
&request_context,
&rotated.user.id,
rotated.session.issued_by_provider.clone(),
)
.await;
state
.sync_auth_store_snapshot_to_spacetime()
.await