Skip to main content

Custom Adapter

Implement the DBAdapter protocol for any database.

from nexfetch_auth.db.adapter import DBAdapter
from nexfetch_auth.db.types import UserData, SessionData, AccountData, VerificationData

class MyAdapter:
async def close(self) -> None: ...

# User
async def create_user(self, email, name, email_verified=False, image=None) -> UserData: ...
async def find_user_by_email(self, email) -> UserData | None: ...
async def find_user_by_id(self, user_id) -> UserData | None: ...
async def update_user(self, user_id, **kwargs) -> UserData | None: ...
async def delete_user(self, user_id) -> None: ...

# Account
async def create_account(self, ...) -> AccountData: ...
async def find_account(self, provider_id, account_id) -> AccountData | None: ...
# ... see db/adapter.py for the full protocol

auth = await nexfetch_auth(secret="...", database=MyAdapter())

See src/nexfetch_auth/db/adapter.py for the complete protocol definition.