Skip to content

Custom Session

Wraps GET /get-session so you can reshape or enrich what clients receive — joining a subscription, a role, a tenant. Mirrors the TS customSession() plugin.

Enable

python
from better_auth import BetterAuth
from better_auth.plugins_ext import CustomSessionPlugin

async def with_plan(session, ctx):
    return {**session, "plan": "pro"}

auth = BetterAuth(
    secret="a-strong-32-character-minimum-secret",
    plugins=[CustomSessionPlugin(with_plan)],
)

Options

OptionTypeDefaultDescription
fncallablerequired (positional)(session, ctx) -> dict, returns the payload clients receive.
should_mutate_list_device_sessions_endpointboolFalseAlso apply fn to each entry of Multi-Session's list-device-sessions.

Endpoints

Overrides the existing route:

MethodPath
GET/get-session

Notes

  • Deliberate simplification: TS's fn also receives a third options argument used only for type inference; the Python callable takes (session, ctx).

MIT licensed · API-compatible with better-auth