[lib.api-client] automatic logout when invalid authentication
This commit is contained in:
parent
1d6ec8c5d1
commit
5e5fff8545
|
@ -53,14 +53,21 @@ export default class APIClient{
|
||||||
this.received = true;
|
this.received = true;
|
||||||
|
|
||||||
/* Try to parse JSON */
|
/* Try to parse JSON */
|
||||||
try{ _response = JSON.parse(_response); }catch(e){ _callback({error: -1}); }
|
try{ _response = JSON.parse(_response); }catch(e){ _callback({error: -2}); }
|
||||||
|
|
||||||
|
/* If authentication failed -> logout user*/
|
||||||
|
if( typeof _response.error === 'number' && _response.error === -1 ){
|
||||||
|
auth.token = null;
|
||||||
|
document.location = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
/* Launch @_callback with response */
|
/* Launch @_callback with response */
|
||||||
_callback(_response);
|
_callback(_response);
|
||||||
|
|
||||||
}.bind(persist);
|
}.bind(persist);
|
||||||
|
|
||||||
this.xhr_driver.onclose = function(){ !this.received && _callback({ error: -2 }); }.bind(persist);
|
this.xhr_driver.onclose = function(){ !this.received && _callback({ error: -3 }); }.bind(persist);
|
||||||
|
|
||||||
|
|
||||||
return this.xhr_driver.send({
|
return this.xhr_driver.send({
|
||||||
|
|
Loading…
Reference in New Issue