mirror of
https://github.com/retailcrm/NelmioApiDocBundle.git
synced 2025-02-10 11:39:25 +03:00
Cache authorization in local storage.
This commit is contained in:
parent
61b1ed35ad
commit
31ef0bdc58
@ -21,5 +21,30 @@ window.onload = () => {
|
|||||||
layout: 'StandaloneLayout'
|
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;
|
window.ui = ui;
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user