diff --git a/src/backend/app/auth/auth_routes.py b/src/backend/app/auth/auth_routes.py index 573f173c0f..c428cdfb9c 100644 --- a/src/backend/app/auth/auth_routes.py +++ b/src/backend/app/auth/auth_routes.py @@ -141,35 +141,33 @@ async def my_data( user_data(dict): The dict of user data. """ # Save user info in User table - user = await user_crud.get_user(db, user_data["id"]) + user = await user_crud.get_user(db, user_data.id) if not user: - user_by_username = await user_crud.get_user_by_username( - db, user_data["username"] - ) + user_by_username = await user_crud.get_user_by_username(db, user_data.username) if user_by_username: raise HTTPException( status_code=400, detail=( - f"User with this username {user_data['username']} already exists. " + f"User with this username {user_data.username} already exists. " "Please contact the administrator." ), ) # Add user to database db_user = DbUser( - id=user_data["id"], - username=user_data["username"], - profile_img=user_data["img_url"], + id=user_data.id, + username=user_data.username, + profile_img=user_data.img_url, ) db.add(db_user) db.commit() # Append role - user_data["role"] = db_user.role + user_data.role = db_user.role else: - if user_data.get("img_url"): - user.profile_img = user_data["img_url"] + if user_data.img_url: + user.profile_img = user_data.img_url db.commit() # Append role - user_data["role"] = user.role + user_data.role = user.role - return JSONResponse(content={"user_data": user_data}, status_code=200) + return user_data diff --git a/src/backend/app/auth/roles.py b/src/backend/app/auth/roles.py index af0c6aa0bb..b46ecb5038 100644 --- a/src/backend/app/auth/roles.py +++ b/src/backend/app/auth/roles.py @@ -22,7 +22,7 @@ and always return an AuthUser object in a standard format. """ -from typing import Optional +from typing import Optional, Union from fastapi import Depends, HTTPException from loguru import logger as log @@ -50,7 +50,7 @@ async def get_uid(user_data: AuthUser) -> int: async def check_super_admin( db: Session, - user: [AuthUser, int], + user: Union[AuthUser, int], ) -> DbUser: """Database check to determine if super admin role.""" if isinstance(user, int): @@ -81,7 +81,7 @@ async def super_admin( async def check_org_admin( db: Session, - user: [AuthUser, int], + user: Union[AuthUser, int], project: Optional[DbProject], org_id: Optional[int], ) -> DbUser: @@ -98,8 +98,8 @@ async def check_org_admin( await check_org_exists(db, org_id) # If user is admin, skip checks - if await check_super_admin(db, user): - return user + if db_user := await check_super_admin(db, user): + return db_user return ( db.query(organisation_managers) diff --git a/src/frontend/src/utilfunctions/login.ts b/src/frontend/src/utilfunctions/login.ts index a3306379dd..0d6f2072e6 100644 --- a/src/frontend/src/utilfunctions/login.ts +++ b/src/frontend/src/utilfunctions/login.ts @@ -34,10 +34,10 @@ export const createLoginWindow = (redirectTo) => { .then((resp) => resp.json()) .then((userRes) => { const params = new URLSearchParams({ - username: userRes.user_data.username, + username: userRes.username, osm_oauth_token: res.access_token, - id: userRes.user_data.id, - picture: userRes.user_data.img_url, + id: userRes.id, + picture: userRes.img_url, redirect_to: redirectTo, }).toString(); const redirectUrl = `/osmauth?${params}`;