mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-09 02:59:27 +03:00
Merge pull request #1456 from cyberemissary/cache-authorization
Cache authorization in local storage.
This commit is contained in:
commit
846e2e3ae4
@ -21,5 +21,30 @@ window.onload = () => {
|
||||
layout: 'StandaloneLayout'
|
||||
});
|
||||
|
||||
const storageKey = 'nelmio_api_auth';
|
||||
|
||||
// if we have auth in storage use it
|
||||
if (sessionStorage.getItem(storageKey)) {
|
||||
try {
|
||||
ui.authActions.authorize(JSON.parse(sessionStorage.getItem(storageKey)));
|
||||
} catch (ignored) {
|
||||
// catch any errors here so it does not stop script execution
|
||||
}
|
||||
}
|
||||
|
||||
// hook into authorize to store the auth in local storage when user performs authorization
|
||||
const currentAuthorize = ui.authActions.authorize;
|
||||
ui.authActions.authorize = function (payload) {
|
||||
sessionStorage.setItem(storageKey, JSON.stringify(payload));
|
||||
return currentAuthorize(payload);
|
||||
};
|
||||
|
||||
// hook into logout to clear auth from storage if user logs out
|
||||
const currentLogout = ui.authActions.logout;
|
||||
ui.authActions.logout = function (payload) {
|
||||
sessionStorage.removeItem(storageKey);
|
||||
return currentLogout(payload);
|
||||
};
|
||||
|
||||
window.ui = ui;
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user