redirect to auth

This commit is contained in:
kurpfish
2021-08-24 13:17:13 +03:00
parent 1a19ae5160
commit 11616b8a38
9 changed files with 39 additions and 25 deletions

View File

@ -1,15 +1,17 @@
export const withAuthRedirect = actionCall => ({link, index, history, role}) => {
export const withAuthRedirect = actionCall => ({link, index, history, role, logout}) => {
return actionCall(link, index)
.then(res => {
if(res.status && res.status == 401) {
localStorage.clear();
history.push(role === 'ROLE_DEV' ? '/authdev' : '/auth')
logout();
history.push(role === 'ROLE_DEV' ? '/authdev' : '/auth') ;
}
return res;
})
.catch(err => {
localStorage.clear();
localStorage.clear();
logout();
history.push(role === 'ROLE_DEV' ? '/authdev' : '/auth');
})
}

View File

@ -13,7 +13,9 @@ export const fetchProfile = withAuthRedirect(async (link, index) => {
let data = await response.json()
return data
} catch (error) {}
} catch (error) {
console.log('Query error', error)
}
})
export const fetchSkills = withAuthRedirect(async (link) => {
@ -29,7 +31,9 @@ export const fetchSkills = withAuthRedirect(async (link) => {
let data = await response.json()
return data
} catch (error) {}
} catch (error) {
console.log('Query error', error)
}
})
export const fetchItemsForId = withAuthRedirect(async (link, id) => {
@ -46,7 +50,9 @@ export const fetchItemsForId = withAuthRedirect(async (link, id) => {
let data = await response.json()
return data
} catch (error) {}
} catch (error) {
console.log('Query error', error)
}
})
export const fetchForm = withAuthRedirect(async (link, info) => {
@ -63,7 +69,9 @@ export const fetchForm = withAuthRedirect(async (link, info) => {
})
return response
} catch (error) {}
} catch (error) {
console.log('Query error', error)
}
})
export const fetchAuth = async ({ username, password, dispatch, catchError }) => {