2.0 KiB
2.0 KiB
Walkthrough - Logout Functionality
I have implemented the logout functionality in the Employee Portal.
Changes Made
Authentication State
- Added a
logout()function in auth_state.dart to reset all global session variables:isLoggedInset tofalseloggedInNik,loggedInName,loggedInImage,loggedInPositionset tonull
Layout
- Implemented a confirmation dialog in root_layout.dart.
- Connected the logout button (using
LucideIcons.logOut) to trigger the dialog. - Clicking "OK" in the dialog will:
- Call the
logout()function. - Pop the dialog.
- Navigate the user back to the
/loginpage.
- Call the
Router
- Enhanced the
redirectlogic in main.dart to enforce authentication:- If a user is not logged in (
isLoggedIn == false), they are strictly redirected to/loginfor any protected route. - If a user is logged in, they are redirected away from
/loginto the dashboard. - This prevents users from using the browser's "back" button to return to the dashboard after logging out.
- If a user is not logged in (
Verification Results
Code Quality
- Verified that all necessary imports are present (
go_router.dart,auth_state.dart). - Fixed class structure issues in
root_layout.dart.
Logic Verification
- The logout flow correctly handles session clearing before navigation.
- The use of
context.go('/login')ensures that the user is redirected to the login page and cannot easily navigate back to protected routes (as theredirectlogic inmain.dartwill catch them ifisLoggedInis false).
Note
Since I cannot run the application in a live browser for this task, I have verified the implementation through code analysis.