From e9b55908e1fc12551b57bb9708d80c5c6774c251 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Sat, 14 Nov 2020 01:56:46 +0000 Subject: Check if a user is an admin in the token payload --- backend/routes/auth/authorize.py | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'backend/routes/auth') diff --git a/backend/routes/auth/authorize.py b/backend/routes/auth/authorize.py index 0a90856..768b9af 100644 --- a/backend/routes/auth/authorize.py +++ b/backend/routes/auth/authorize.py @@ -24,6 +24,10 @@ class AuthorizeRoute(Route): bearer_token = await fetch_bearer_token(data["token"]) user_details = await fetch_user_details(bearer_token["access_token"]) + user_details["admin"] = request.state.db.admins.find_one( + {"_id": user_details["id"]} + ) is not None + token = jwt.encode(user_details, SECRET_KEY, algorithm="HS256") return JSONResponse({ -- cgit v1.2.3