This commit is contained in:
parent
6cd2fc0f80
commit
4ca9491824
|
@ -35,7 +35,7 @@ poetry run python server.py
|
|||
|
||||
### Auth
|
||||
|
||||
Put the header 'Authorization' with token from signIn query or registerUser mutation.
|
||||
Put the header 'Authorization' with token from signIn query or registerUser mutation. Setup `WEBHOOK_SECRET` env var
|
||||
|
||||
### Viewed
|
||||
|
||||
|
|
8
main.py
8
main.py
|
@ -6,6 +6,7 @@ from ariadne.asgi import GraphQL
|
|||
from starlette.applications import Starlette
|
||||
from starlette.endpoints import HTTPEndpoint, Request
|
||||
from starlette.responses import JSONResponse
|
||||
from starlette.routing import Route
|
||||
|
||||
from resolvers.author import create_author
|
||||
from services.rediscache import redis
|
||||
|
@ -46,7 +47,7 @@ class WebhookEndpoint(HTTPEndpoint):
|
|||
if data:
|
||||
auth = request.headers.get("Authorization")
|
||||
if auth:
|
||||
# TODO: check Authorization header
|
||||
if auth == os.environ.get("WEBHOOK_SECRET"):
|
||||
# Extract user_id and slug
|
||||
user_id = data["user"]["id"]
|
||||
email_slug = data["user"]["email"].replace(".", "-").split("@").pop()
|
||||
|
@ -57,6 +58,5 @@ class WebhookEndpoint(HTTPEndpoint):
|
|||
return JSONResponse({"status": "error", "message": str(e)}, status_code=500)
|
||||
|
||||
|
||||
app = Starlette(debug=True, on_startup=[start_up], on_shutdown=[shutdown])
|
||||
app.mount("/", GraphQL(schema, debug=True))
|
||||
app.mount("/new-author", WebhookEndpoint)
|
||||
routes = [Route("/", GraphQL(schema, debug=True)), Route("/new-author", WebhookEndpoint)]
|
||||
app = Starlette(routes=routes, debug=True, on_startup=[start_up], on_shutdown=[shutdown])
|
||||
|
|
Loading…
Reference in New Issue
Block a user