File tree Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Expand file tree Collapse file tree 1 file changed +28
-1
lines changed Original file line number Diff line number Diff line change @@ -52,7 +52,34 @@ export const Canvas = () => {
5252 const [ hoveredHandle , setHoveredHandle ] = useState ( null ) ; // { id, dir }
5353
5454 const handleLogout = async ( ) => {
55- // placeholder
55+ try {
56+ const token = localStorage . getItem ( "token" ) ;
57+ if ( ! token ) {
58+ toast . error ( "You are not logged in." ) ;
59+ return ;
60+ }
61+
62+ const res = await fetch ( "http://localhost:3000/api/auth/logout" , {
63+ method : "POST" ,
64+ headers : { "Content-Type" : "application/json" } ,
65+ body : JSON . stringify ( { token } ) ,
66+ } ) ;
67+
68+ if ( ! res . ok ) {
69+ const data = await res . json ( ) . catch ( ( ) => ( { } ) ) ;
70+ toast . error ( data . message || "Logout failed" ) ;
71+ return ;
72+ }
73+
74+ // Clear auth state and redirect
75+ localStorage . removeItem ( "token" ) ;
76+ setIsLoggedIn ( false ) ;
77+ toast . success ( "Logged out successfully" ) ;
78+ window . location . href = "/" ;
79+ } catch ( err ) {
80+ console . error ( "Logout error:" , err ) ;
81+ toast . error ( "Logout failed. Please try again." ) ;
82+ }
5683 } ;
5784
5885 // --- Helpers ---
You can’t perform that action at this time.
0 commit comments