Spaces:
Sleeping
Sleeping
msmhmorsi
commited on
Commit
·
44ce6d8
1
Parent(s):
c4db682
change cookie name
Browse files
app.py
CHANGED
@@ -26,12 +26,12 @@ def greet_json(request: Request):
|
|
26 |
async def auth(request: Request, response: Response):
|
27 |
data = await request.json()
|
28 |
if data.get("username") == "admin" and data.get("password") == "password":
|
29 |
-
response.set_cookie(key="
|
30 |
return {"message": "Authentication successful"}
|
31 |
raise HTTPException(status_code=401, detail="Invalid credentials")
|
32 |
|
33 |
@app.get("/protected")
|
34 |
-
def protected_route(
|
35 |
-
if
|
36 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
37 |
return {"message": "Access granted to protected route"}
|
|
|
26 |
async def auth(request: Request, response: Response):
|
27 |
data = await request.json()
|
28 |
if data.get("username") == "admin" and data.get("password") == "password":
|
29 |
+
response.set_cookie(key="comfy_session", value="dummy_session_value")
|
30 |
return {"message": "Authentication successful"}
|
31 |
raise HTTPException(status_code=401, detail="Invalid credentials")
|
32 |
|
33 |
@app.get("/protected")
|
34 |
+
def protected_route(comfy_session: Optional[str] = Cookie(None)):
|
35 |
+
if comfy_session != "dummy_session_value":
|
36 |
raise HTTPException(status_code=401, detail="Unauthorized")
|
37 |
return {"message": "Access granted to protected route"}
|