Data provider
@dotpress/auth stores nothing itself. A data provider, an object of a few functions, reads your users and stores the refresh tokens in your database, with the library of your choice.
The methods
findUserById() must return undefined for a deleted, disabled or banned account. It is called on every request: the user is logged out at once, and their sessions are revoked at the next refresh.
Return only what the handlers need from findUserById(): it becomes ctx.user, and is returned by GET /auth/me. Never the password hash.
The refresh tokens table
A refresh token is stored by its SHA-256 hash, never in clear. The tokens of a session share a familyId, the session ID:
Expired tokens can be deleted by a scheduled job: DELETE FROM refresh_tokens WHERE expires_at < now().
An SQL data provider
The data provider of the Tasks API example, on SQLite. The queries are the same on PostgreSQL or MySQL, with their placeholders:
findUserById() and findUserIdentifiers() come from the users repository of the app: the user table stays yours, with your columns.
The type of the user
The type of ctx.user is the AuthUser interface, which you complete once, with module augmentation:
findUserById() must return this type. See Protecting routes.
In tests
A data provider over a Map is enough for the tests. The Auth example has one, in src/store.ts, used both by the app in development and by the tests.