Conversation
Adds a complete, framework-uniform session lifecycle event system that
fires events on three buses simultaneously:
1. CurrentUserService Evented bus (backward-compatible .on() listeners)
2. EventsService Evented bus (local service-level listeners)
3. Universe service bus (cross-engine listeners — recommended for engines)
Events fired:
session.authenticated — on login / session restore (SessionService)
session.invalidated — on logout (SessionService)
session.terminated — alias for session.invalidated (backward compat)
user.loaded — after user + org fully loaded (CurrentUserService)
user.updated — after in-session profile refresh (CurrentUserService)
user.deauthenticated — semantic logout alias for integrations (SessionService)
user.organization_switched — on org switch (CurrentUserService)
Changes:
- session.js: inject universe + events services; fire session.authenticated
in handleAuthentication(), fire session.invalidated / user.deauthenticated
in handleInvalidation() with session duration; add _fireSessionEvent()
helper that broadcasts on both events service and universe directly
- current-user.js: inject universe service; call events.trackUserLoaded()
and universe.trigger('user.loaded') in setUser(); add refreshUser() and
switchOrganization() helpers that fire user.updated and
user.organization_switched respectively
- events.js: add trackSessionAuthenticated(), trackUserUpdated(),
trackOrganizationSwitched(); trackSessionTerminated() now also fires
user.deauthenticated; full JSDoc for all session lifecycle events
Previously trackUserLoaded() and trackSessionTerminated() existed but were
never called. All session lifecycle tracking methods are now wired up.
The previous commit introduced a handleInvalidation() override that fired session lifecycle events but did not call super, meaning the parent ember-simple-auth behaviour (redirecting the browser to rootURL after logout via handleSessionInvalidated) was silently dropped. This would have caused the app to stay on the current page after logout instead of redirecting to the login screen — a critical breakage. Fix: call super.handleInvalidation(routeAfterInvalidation) first, then fire our session lifecycle events. The super call is always safe here because it only performs a redirect/reload and has no return value we need to act on.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Implements a complete, framework-uniform session lifecycle event system across the three core services (
session,current-user,events). All events are fired on three buses simultaneously so any listener — whether in the main app, an Ember Engine, or a third-party integration — receives them reliably.Event buses
CurrentUserService(Evented)currentUser.on("user.loaded", fn)EventsService(Evented)events.on("user.loaded", fn)Universeuniverse.on("user.loaded", fn)Events added
session.authenticatedSessionService.handleAuthentication()session.invalidatedSessionService.handleInvalidation()session.terminatedSessionService.handleInvalidation()user.loadedCurrentUserService.setUser()user.updatedCurrentUserService.refreshUser()user.deauthenticatedSessionService.handleInvalidation()user.organization_switchedCurrentUserService.switchOrganization()Previously broken
trackUserLoaded()andtrackSessionTerminated()existed inEventsServicebut were never called. This PR wires them up properly.Motivation
This unblocks clean integration of third-party services (Intercom, PostHog, Attio, etc.) in Ember Engines without resorting to
addObserverhacks on the session service, which does not extendEvented.Related
fleetbase/internalsPR:feature/schedule-call-menu-item— Intercom lifecycle initializer updated to consumeuser.loadedanduser.deauthenticatedfrom the universe bus