User Login
Call the create_new_session
function: API Reference
await supertokens_fastapi.create_new_session(request, user_id, jwt_payload, session_data);
jwt_payload
(type dict
) should not contain any sensitive information. This information will be accessible from the frontend.
session_data
(type dict
) is stored in your database and can contain any information.
- This will attach all relevant cookies and header to the
response
sent by your function.
Example
from supertokens_fastapi import create_new_session
from fastapi.requests import Request
from fastapi.responses import JSONResponse
@app.post('/login')
async def login(request: Request):
user_id = 'userId'
jwt_payload = {'name': 'spooky action at a distance'}
session_data = {'awesomeThings': ['programming', 'javascript', 'supertokens']}
await create_new_session(request, user_id, jwt_payload, session_data)
return JSONResponse(content={'userId': user_id}, status_code=200)