Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@
# This allows the frontend (running on localhost:5173) to make requests to this backend
app.add_middleware(
CORSMiddleware,
allow_origins=["http://localhost:5173", "http://127.0.0.1:5173"],
allow_origins=[
"http://localhost:5173",
"http://127.0.0.1:5173",
"http://localhost",
"http://127.0.0.1",
],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
Expand Down Expand Up @@ -72,7 +77,7 @@ async def get_current_user(request: Request, session_id: str = Query(...)):
@app.get("/protected")
async def protected_route(user=Depends(get_current_user)):
# Retrieve detailed user information from Clerk
user_details = clerk_client.users.list(user_id=[user.user_id])
user_details = clerk_client.users.get(user_id=user.user_id)
print(80*'-')
print(f"session object: {user}") # user is ClerkUser(user)
print(80*'-')
Expand All @@ -81,10 +86,10 @@ async def protected_route(user=Depends(get_current_user)):

# Return a personalized message using the user's first name
return {
"message": f"Hello, {user_details[0].first_name}!",
"message": f"Hello, {user_details.first_name}!",
# Uncomment the following lines if you want to include more user details in the response
# "user_id": user_details[0].user_id,
# "email": user_details[0].email_addresses[0].email_address if user_details[0].email_addresses else None,
# "user_id": user_details.user_id,
# "email": user_details.email_addresses[0].email_address if user_details.email_addresses else None,
}

# Root route to check if the server is running
Expand All @@ -95,4 +100,4 @@ async def root():
# Run the FastAPI application using uvicorn when this script is executed directly
if __name__ == "__main__":
import uvicorn
uvicorn.run(app, host="127.0.0.1", port=8069)
uvicorn.run(app, host="127.0.0.1", port=8069)