feat(garmin): 增加「退出 Garmin 账号」功能,删除已保存令牌以便重新登录

backend: services/garmin.py 新增 delete_token(),删除 garmin_tokens 行并 forget_client 丢弃缓存会话;routes/garmin.py 新增 POST /api/garmin/disconnect(require_auth),返回 ok + 提示文案。
frontend: api.ts 增加 disconnectGarmin();SyncPage 增加「退出 Garmin 账号」按钮(带二次确认弹窗);DataSync.css 增加危险色样式。
设计:仅删除 OAuth 令牌,保留 users.garmin_email,下次重登只需密码;已同步的健康数据不受影响。
This commit is contained in:
ericwyuan
2026-08-28 15:13:32 +08:00
parent 11869c6a8d
commit bec45414a7
5 changed files with 91 additions and 0 deletions

View File

@@ -56,6 +56,22 @@ def auth_status():
return jsonify({"hasToken": garmin_svc.has_token(g.user_id)})
@bp.route("/disconnect", methods=["POST"])
@require_auth
def disconnect():
"""Drop the stored Garmin token so the next sync must re-authenticate.
Deletes the OAuth token (the UI calls this a "退出 Garmin 账号"). garmin_email
stays on the user record, so re-login only needs the password again. Already
synced health data is untouched.
"""
garmin_svc.delete_token(g.user_id)
return jsonify({
"ok": True,
"message": "已退出 Garmin 账号,已保存的授权令牌已删除,下次同步需重新登录获取新令牌。",
})
@bp.route("/login", methods=["POST"])
@require_auth
def login():