busyorg / busy

Blockchain-based social network where anyone can earn rewards 🚀
https://busy.org/
MIT License
359 stars 252 forks source link

Instant logout #1507

Closed bonustrack closed 6 years ago

bonustrack commented 6 years ago

Now it take few second after click on Logout to actually see yourself logged out. It feel like it's not working and may confuse user. We should show user logged out directly when he click on it. image

tonimese commented 6 years ago

Maybe also redirect user to steemconnect.com/dashboard to logout there

Sekhmet commented 6 years ago

It should be fairly easy to implement this feature. I made proof of concept. Only thing left to do is to update logout action to be just single value @auth/LOGOUT and use it inside of authReducer.

diff --git a/src/client/auth/authActions.js b/src/client/auth/authActions.js
index 27fe3f6..70d9fe9 100644
--- a/src/client/auth/authActions.js
+++ b/src/client/auth/authActions.js
@@ -57,13 +57,15 @@ export const reload = () => (dispatch, getState, { steemConnectAPI }) =>
     },
   });

-export const logout = () => (dispatch, getState, { steemConnectAPI }) =>
+export const logout = () => (dispatch, getState, { steemConnectAPI }) => {
+  steemConnectAPI.revokeToken();
+  Cookie.remove('access_token');
+
+  // TODO: LOGOUT doesn't have to be async anymore (START, SUCCESS, ERROR)
   dispatch({
     type: LOGOUT,
-    payload: {
-      promise: steemConnectAPI.revokeToken().then(() => Cookie.remove('access_token')),
-    },
   });
+};

 export const getUpdatedSCUserMetadata = () => (dispatch, getState, { steemConnectAPI }) =>
   dispatch({
diff --git a/src/client/auth/authReducer.js b/src/client/auth/authReducer.js
index 5bca4a0..ba7f9bb 100644
--- a/src/client/auth/authReducer.js
+++ b/src/client/auth/authReducer.js
@@ -53,6 +53,7 @@ export default (state = initialState, action) => {
         ...state,
         isReloading: false,
       };
+    // TODO: Replace those two with single non-async action
     case types.LOGOUT_START:
       return {
         ...state,