[PR #25817] refactor(web): unify logout functionality with centralized modal confirmation #31216

Closed
opened 2026-02-21 20:49:02 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/langgenius/dify/pull/25817

State: closed
Merged: No


Fixes #25815

Summary

This PR implements a unified logout confirmation modal across the entire Dify web application, preventing accidental logouts and consolidating scattered logout logic into a single, maintainable solution.

What This PR Does

1. Prevents Accidental Logouts

  • Added confirmation modal for all logout actions (except where explicitly skipped)
  • Consistent warning message asking users to confirm before logging out
  • Unified modal design using existing Confirm component for consistency

2. Centralized Logout Logic

  • Created useLogout hook: Single source of truth for all logout functionality
  • Unified LogoutModal component: Reusable confirmation dialog
  • Integrated with modal context: Leverages existing modal infrastructure

3. Fixed Inconsistent Behaviors

  • Consistent localStorage cleanup: All scenarios now properly clear:
    • Standard tokens: setup_status, console_token, refresh_token
    • Education items: education-reverify-*, education-expired-* (always cleared)
    • WebApp tokens: token, webapp_access_token (when applicable)
  • Source tracking: Added source parameter for analytics

4. Migrated All 7 Logout Locations

  • Header dropdown menu
  • Account settings avatar
  • Share app menu
  • Education apply page
  • Delete account flow (auto-skip confirmation)
  • Email change modal (auto-skip confirmation)
  • Chat sidebar

Testing

Comprehensive test coverage added:

  • Unit tests: 13 test cases for useLogout hook
  • Integration tests: 10 test cases covering all scenarios
  • 100% code coverage for logout functionality
  • All tests passing

Screenshots

Before After
No confirmation modal - accidental logout risk Confirmation modal prevents accidental logouts
7 different implementations Single unified hook
Inconsistent localStorage cleanup Consistent cleanup across all scenarios

Breaking Changes

None - This is 100% backward compatible:

  • Delete account and email change flows still skip confirmation (as before)
  • All redirect behaviors preserved
  • All success callbacks maintained
  • WebApp vs Console logic unchanged

Checklist

  • This change requires a documentation update, included: Dify Document
  • I understand that this PR may be closed in case there was no previous discussion or issues.
  • I have added a test for each change that was introduced
  • I have updated the documentation accordingly
  • I ran dev/reformat(backend) and cd web && npx lint-staged(frontend) to appease the lint gods
**Original Pull Request:** https://github.com/langgenius/dify/pull/25817 **State:** closed **Merged:** No --- Fixes #25815 ## Summary This PR implements a unified logout confirmation modal across the entire Dify web application, preventing accidental logouts and consolidating scattered logout logic into a single, maintainable solution. ## What This PR Does ### 1. Prevents Accidental Logouts - **Added confirmation modal** for all logout actions (except where explicitly skipped) - **Consistent warning message** asking users to confirm before logging out - **Unified modal design** using existing Confirm component for consistency ### 2. Centralized Logout Logic - **Created `useLogout` hook**: Single source of truth for all logout functionality - **Unified `LogoutModal` component**: Reusable confirmation dialog - **Integrated with modal context**: Leverages existing modal infrastructure ### 3. Fixed Inconsistent Behaviors - **Consistent localStorage cleanup**: All scenarios now properly clear: - Standard tokens: `setup_status`, `console_token`, `refresh_token` - Education items: `education-reverify-*`, `education-expired-*` (always cleared) - WebApp tokens: `token`, `webapp_access_token` (when applicable) - **Source tracking**: Added source parameter for analytics ### 4. Migrated All 7 Logout Locations - ✅ Header dropdown menu - ✅ Account settings avatar - ✅ Share app menu - ✅ Education apply page - ✅ Delete account flow (auto-skip confirmation) - ✅ Email change modal (auto-skip confirmation) - ✅ Chat sidebar ## Testing Comprehensive test coverage added: - **Unit tests**: 13 test cases for `useLogout` hook - **Integration tests**: 10 test cases covering all scenarios - **100% code coverage** for logout functionality - **All tests passing** ## Screenshots | Before | After | |--------|-------| | No confirmation modal - accidental logout risk | Confirmation modal prevents accidental logouts | | 7 different implementations | Single unified hook | | Inconsistent localStorage cleanup | Consistent cleanup across all scenarios | ## Breaking Changes **None** - This is 100% backward compatible: - Delete account and email change flows still skip confirmation (as before) - All redirect behaviors preserved - All success callbacks maintained - WebApp vs Console logic unchanged ## Checklist - [ ] This change requires a documentation update, included: [Dify Document](https://github.com/langgenius/dify-docs) - [x] I understand that this PR may be closed in case there was no previous discussion or issues. - [x] I have added a test for each change that was introduced - [x] I have updated the documentation accordingly - [x] I ran `dev/reformat`(backend) and `cd web && npx lint-staged`(frontend) to appease the lint gods
yindo added the pull-request label 2026-02-21 20:49:02 -05:00
yindo closed this issue 2026-02-21 20:49:02 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langgenius/dify#31216