Session Object
user_id = session.get_user_id()
- This function does not do any database call.
jwt_payload = session.get_jwt_payload()
- This function does not do any database call.
update_jwt_payload
function: API Reference
new_data = {"key": "value"}
await session.update_jwt_payload(new_data)
- This function will change the current access token
- This function requires a database call each time it's called.
get_session_data
function: API Reference
session_data = await session.get_session_data()
- This function requires a database call each time it's called.
update_session_data
function: API Reference
new_data = {"key": "value"}
await session.update_session_data(new_data)
- This function overwrites the current session data stored for this session.
- This function requires a database call each time it's called.
await session.revoke_session()
- This function deletes the session from the database and clears relevant auth cookies
- If using blacklisting, this will immediately invalidate the JWT access token.
Example
from supertokens_fastapi import supertokens_session, Session
from fastapi import Depends
from fastapi.responses import JSONResponse
@app.post('/test')
async def test_info(session: Session = Depends(supertokens_session)):
user_id = session.get_user_id()
session_data = await session.get_session_data()
new_session_data = {***session_data, newKey: "newVal"}
await session.update_session_data(new_session_data)
payload_data = session.get_jwt_payload()
new_payload = {...payload_data, newKey: "newVal"}
await session.update_jwt_payload(new_payload)
await session.revoke_session()
return JSONResponse(content={'status': 'ok'})