Add Google OAuth configuration and enhance API functionality
- Updated .env.example with WEB_GOOGLE_CLIENT_ID and WEB_GOOGLE_CLIENT_SECRET for Google OAuth. - Modified README.md to reflect changes in docker-compose for unified web and API deployment. - Enhanced auth.py to support NextAuth JWT session cookies. - Improved main.py with lifespan management and additional API endpoints. - Added mod_overview endpoint in mod.py for MOD panel statistics. - Updated docker-compose.yml for local API and web service configurations.
This commit is contained in:
+28
-1
@@ -70,7 +70,34 @@ async def _get_user_from_session_cookie(db: AsyncSession, request: Request) -> d
|
||||
{"token": token},
|
||||
)
|
||||
row = result.mappings().first()
|
||||
return dict(row) if row else None
|
||||
if row:
|
||||
return dict(row)
|
||||
|
||||
# Support NextAuth/Auth.js JWT session cookies when frontend runs in JWT mode.
|
||||
secret = _jwt_secret()
|
||||
if not secret:
|
||||
return None
|
||||
|
||||
try:
|
||||
payload = jwt.decode(token, secret, algorithms=["HS256"])
|
||||
except JWTError:
|
||||
return None
|
||||
|
||||
subject = payload.get("sub") or payload.get("id")
|
||||
if not isinstance(subject, str) or not subject:
|
||||
return None
|
||||
|
||||
role = payload.get("role")
|
||||
if isinstance(role, str) and role:
|
||||
return {
|
||||
"id": subject,
|
||||
"email": payload.get("email"),
|
||||
"name": payload.get("name"),
|
||||
"image": payload.get("picture") or payload.get("image"),
|
||||
"role": role,
|
||||
}
|
||||
|
||||
return await _get_user_by_id(db, subject)
|
||||
|
||||
|
||||
async def resolve_current_user(db: AsyncSession, request: Request) -> dict[str, Any] | None:
|
||||
|
||||
Reference in New Issue
Block a user