### TL;DR
Added session cleanup logic to handle active organization reassignment when user organizations are deleted.
### What changed?
Enhanced the `cleanupUserOrganizations` method in `AuthService` to reassign active organizations for users whose current active organization is being deleted. The method now:
- Identifies users who are members of organizations being deleted
- Finds alternative organizations for each affected user
- Updates their sessions to use a fallback organization or null if no alternatives exist
- Wraps the entire operation in a database transaction for consistency
### How to test?
Run the new test suite:
```bash
bun test app/server/modules/auth/__tests__/auth.cleanup-user-organizations.test.ts
```
The test verifies that when a user's organization is deleted, other members' sessions are properly updated to use their remaining organization memberships as the active organization.
### Why make this change?
Prevents orphaned session references when organizations are deleted. Without this change, users could have sessions pointing to non-existent organizations as their active workspace, leading to potential application errors or inconsistent state.
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
## Release Notes
* **Bug Fixes**
* Improved organization deletion handling. When an organization is deleted, user sessions are now automatically reassigned to a valid fallback organization, ensuring session state consistency and preventing invalid organization references.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
test: use better-auth built-in test plugin
refactor: map auth errors server side
refactor: native trusted providers callback usage
<!-- This is an auto-generated comment: release notes by coderabbit.ai -->
## Summary by CodeRabbit
## Release Notes
* **New Features**
* Enhanced SSO authentication error messaging with specific guidance for different failure scenarios (account linking required, email verification needed, banned accounts, invite-only access).
* **Chores**
* Updated authentication dependencies to version 1.5.0.
* **Tests**
* Extended test coverage for SSO error code handling and authentication scenarios.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
* refactor: move migrations to new structure
* refactor: convert all findMany to new structure
* fix(backups-schedule): missing null matching for last backup status
* chore: move root lib to server
* feat(db): add support for multiple users and organizations
* feat: backfill entities with new organization id
* refactor: filter all backend queries to surface only organization specific entities
* refactor: each org has its own restic password
* test: ensure organization is created
* chore: pr feedbacks
* refactor: filter by org id in all places
* refactor: download restic password from stored db password
* refactor(navigation): use volume id in urls instead of name
* feat: disable registrations
* refactor(auth): bubble up auth error to hono
* refactor: use async local storage for cleaner context sharing
* refactor: enable user registration vs disabling it
* test: multi-org isolation
* chore: final cleanup
* feat: add custom restore target directory
Adds the ability to restore snapshots to a custom directory instead of
only the original path. Closes#12.
Changes:
- Add target parameter to restore API endpoint
- Add directory picker UI in file browser restore dialog
- Add target input field in snapshot restore form
- Create reusable PathSelector component
Note: Run `bun run gen:api-client` after merging to regenerate types.
* refactor: path selector design
* refactor: unify restore snapshot dialogs
* refactor: restore snapshot as a page
* chore: fix liniting issues
* chore(create-notification): remove un-used prop
---------
Co-authored-by: Deepseek1 <Deepseek1@users.noreply.github.com>