From 8a7587eb446494f12ddc4a680d53492ee7f5d8ea Mon Sep 17 00:00:00 2001 From: spwoodcock Date: Tue, 16 Jan 2024 16:26:59 +0000 Subject: [PATCH] fix: add user role to response /me for frontend --- src/backend/app/auth/auth_routes.py | 4 ++++ src/backend/app/auth/osm.py | 6 +++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/app/auth/auth_routes.py b/src/backend/app/auth/auth_routes.py index 205294f224..19d6740e32 100644 --- a/src/backend/app/auth/auth_routes.py +++ b/src/backend/app/auth/auth_routes.py @@ -162,9 +162,13 @@ async def my_data( ) db.add(db_user) db.commit() + # Append role + user_data["role"] = db_user.role else: if user_data.get("img_url"): user.profile_img = user_data["img_url"] db.commit() + # Append role + user_data["role"] = user.role return JSONResponse(content={"user_data": user_data}, status_code=200) diff --git a/src/backend/app/auth/osm.py b/src/backend/app/auth/osm.py index 66d2deda93..95012a96d4 100644 --- a/src/backend/app/auth/osm.py +++ b/src/backend/app/auth/osm.py @@ -24,9 +24,11 @@ from fastapi import Header, HTTPException, Request from loguru import logger as log from osm_login_python.core import Auth -from pydantic import BaseModel +from pydantic import BaseModel, ConfigDict from app.config import settings +from app.models.enums import UserRole + if settings.DEBUG: # Required as callback url is http during dev @@ -35,10 +37,12 @@ class AuthUser(BaseModel): """The user model returned from OSM OAuth2.""" + model_config = ConfigDict(use_enum_values=True) id: int username: str img_url: Optional[str] + role: Optional[UserRole] async def init_osm_auth():