7b62c2f8b4
## H5 底部导航修复 (Bug #10) - 精简 App.vue,移除重复 tabbar,仅保留全局样式 - uni-page 设置 height: calc(100% - 50px) + overflow-y: auto - 内容区域精确停在底部导航上方,独立滚动不再叠加 - 恢复 custom-tab-bar 组件 ## 项目进度文档 - PROGRESS.md 更新至 10 个 Bug 修复 - 新增 H5 底部导航修复记录 - 新增历史变更条目
44 lines
1.3 KiB
Python
44 lines
1.3 KiB
Python
from fastapi import HTTPException, Depends, Header
|
|
from fastapi.security import HTTPBearer, HTTPAuthorizationCredentials
|
|
from app.core.security import decode_token
|
|
from typing import Optional
|
|
|
|
security = HTTPBearer(auto_error=False)
|
|
|
|
|
|
async def get_current_user_id(
|
|
authorization: Optional[str] = Header(None, alias="Authorization"),
|
|
cred: Optional[HTTPAuthorizationCredentials] = Depends(security),
|
|
) -> str:
|
|
token = None
|
|
if cred:
|
|
token = cred.credentials
|
|
elif authorization and authorization.startswith("Bearer "):
|
|
token = authorization[7:]
|
|
|
|
if not token:
|
|
raise HTTPException(status_code=401, detail="Missing or invalid token")
|
|
|
|
payload = decode_token(token)
|
|
if not payload:
|
|
raise HTTPException(status_code=401, detail="Invalid or expired token")
|
|
|
|
return payload.get("sub")
|
|
|
|
|
|
async def get_current_user(
|
|
cred: HTTPAuthorizationCredentials = Depends(security),
|
|
) -> dict:
|
|
if not cred:
|
|
raise HTTPException(status_code=401, detail="Missing or invalid token")
|
|
|
|
payload = decode_token(cred.credentials)
|
|
if not payload:
|
|
raise HTTPException(status_code=401, detail="Invalid or expired token")
|
|
|
|
return {
|
|
"id": payload.get("sub"),
|
|
"tier": payload.get("tier", "free"),
|
|
"role": payload.get("role", "user"),
|
|
}
|