Skip to content

Commit

Permalink
(feat) Redirect users to the page they were on before being logged out (
Browse files Browse the repository at this point in the history
#931)

* save initialUrl in the sessionStorage before logging out
  • Loading branch information
coderatomy authored Oct 20, 2023
1 parent 168945b commit a558469
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
3 changes: 3 additions & 0 deletions zubhub_frontend/zubhub/src/api/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,9 @@ class API {
* @todo - describe method's signature
*/
logout = token => {
const initialUrl = window.location.href
sessionStorage.setItem('initialUrl', initialUrl)

const url = 'rest-auth/logout/';
const method = 'POST';
return this.request({ url, method, token }).then(res => res.json());
Expand Down
10 changes: 9 additions & 1 deletion zubhub_frontend/zubhub/src/store/actions/authActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,15 @@ export const login = args => {
payload: { token: res.key },
});
})
.then(() => args.history.push('/'));
.then(() => {
const initialUrl = sessionStorage.getItem('initialUrl');
if (initialUrl) {
sessionStorage.removeItem('initialUrl')
window.location.href = initialUrl;
} else {
args.history.push('/');
}
});
};
};

Expand Down

0 comments on commit a558469

Please sign in to comment.