feat: Preserve authorization on browser refresh and close/reopen (#5939)

* Add default configuration `preserveAuthorization`

* Add localStorage to auth plugin

* Add persistAuthorization unit tests

* Refactor persistAuthorization to use wrapped actions

* Upgrade unit tests to be compatible with jest

* Add persistAuthorization documentation


Co-authored-by: Tim Lai <timothy.lai@gmail.com>
This commit is contained in:
Amir Bitaraf Haghighi
2020-09-12 01:35:37 +04:30
committed by GitHub
parent 48ee32faa1
commit 96aecc8860
9 changed files with 239 additions and 12 deletions

View File

@@ -21,4 +21,17 @@ export function toggle(configName) {
// Hook
export const loaded = () => () => {}
export const loaded = () => ({getConfigs, authActions}) => {
// check if we should restore authorization data from localStorage
const configs = getConfigs()
if (configs.persistAuthorization)
{
const authorized = localStorage.getItem("authorized")
if(authorized)
{
authActions.restoreAuthorization({
authorized: JSON.parse(authorized)
})
}
}
}