webhook-fix
All checks were successful
deploy / deploy (push) Successful in 9s

This commit is contained in:
Untone 2023-11-28 22:13:53 +03:00
parent 0c2af2bdf4
commit 269c0e449f
2 changed files with 6 additions and 3 deletions

View File

@ -44,7 +44,10 @@ class WebhookEndpoint(HTTPEndpoint):
try: try:
data = await request.json() data = await request.json()
if data: if data:
await create_author(data) # Extract user_id and slug
user_id = data["user"]["id"]
slug = data["user"]["preferred_username"] or data["user"]["email"].replace(".", "-").split("@").pop()
await create_author(user_id, slug)
return JSONResponse({"status": "success"}) return JSONResponse({"status": "success"})
except Exception as e: except Exception as e:
return JSONResponse({"status": "error", "message": str(e)}, status_code=500) return JSONResponse({"status": "error", "message": str(e)}, status_code=500)

View File

@ -241,9 +241,9 @@ async def rate_author(_, info, rated_slug, value):
return {} return {}
async def create_author(data): async def create_author(user_id: str, slug: str):
with local_session() as session: with local_session() as session:
# TODO: check Authorization header # TODO: check Authorization header
new_author = Author(**data) new_author = Author(user=user_id, slug=slug)
session.add(new_author) session.add(new_author)
session.commit() session.commit()