Skip to content

Commit

Permalink
fix: add user role to response /me for frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
spwoodcock committed Jan 16, 2024
1 parent e7d8b74 commit 8a7587e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
4 changes: 4 additions & 0 deletions src/backend/app/auth/auth_routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
6 changes: 5 additions & 1 deletion src/backend/app/auth/osm.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down

0 comments on commit 8a7587e

Please sign in to comment.