diff --git a/main.py b/main.py index 49b6e158..3b481169 100644 --- a/main.py +++ b/main.py @@ -44,7 +44,10 @@ class WebhookEndpoint(HTTPEndpoint): try: data = await request.json() 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"}) except Exception as e: return JSONResponse({"status": "error", "message": str(e)}, status_code=500) diff --git a/resolvers/author.py b/resolvers/author.py index 10db8039..6426fa8f 100644 --- a/resolvers/author.py +++ b/resolvers/author.py @@ -241,9 +241,9 @@ async def rate_author(_, info, rated_slug, value): return {} -async def create_author(data): +async def create_author(user_id: str, slug: str): with local_session() as session: # TODO: check Authorization header - new_author = Author(**data) + new_author = Author(user=user_id, slug=slug) session.add(new_author) session.commit()