Skip to content

Server: Replace passport with Dito.js' own login and session handling - #326

Merged
lehni merged 1 commit into
mainfrom
refactor/remove-passport
Oct 17, 2026
Merged

lehni merged 1 commit into
mainfrom
refactor/remove-passport

Conversation

@lehni

@lehni lehni commented Oct 16, 2026 •

Copy link
Copy Markdown
Contributor

Closes #325.

  • UserMixin.login() checks the credentials of the request body itself, with the same errors as before.
  • handleUser() restores session users and defines ctx.login(), ctx.logout(), ctx.isAuthenticated() and ctx.isUnauthenticated(), with the login and logout events. It's always installed.
  • Sessions keep the passport.user key, so existing sessions stay valid.
  • app.passport is deprecated and has no effect.
  • Drops koa-passport and passport-local.

Behaviour changes, also in the changelog:

  • Credentials are only read from the request body. Passport's local strategy also read them from the query string.
  • Logging in a model that isn't a user throws, as with Passport, and before:login only fires for logins that can succeed.
  • UsersController only treats users of its own model class as logged in, not users of sub-classes, which have their own tables and ids.
  • UserMixin.sessionQuery() is internal; sessionScope still sets the scopes.
  • Passport's ctx.req.user mirror and custom Passport strategies through Dito.js are gone.

The tests were written against Passport first and pass there, except the one for query-string credentials. They cover restoring sessions in Passport's format, session regeneration on login, logout, scoped and deleted users, session: false, the events, and transacted logins that fail.

@lehni
lehni force-pushed the refactor/remove-passport branch 5 times, most recently from 2d19bd9 to 4d77466 Compare October 16, 2026 23:00
@lehni
lehni added this pull request to stack #341 October 16, 2026 23:05
@lehni
lehni force-pushed the refactor/remove-passport branch 2 times, most recently from f1ee7d4 to db17729 Compare October 17, 2026 01:25
- Read login credentials from the request body in UserMixin.login()
- Restore session users and define ctx.login(), ctx.logout() and ctx.isAuthenticated() in handleUser(), always installed
- Keep the passport.user session key, so existing sessions stay valid
- Deprecate app.passport, which has no effect anymore
- Drop the koa-passport and passport-local dependencies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Replace koa-passport with Dito.js' own login and session handling

1 participant