# HG changeset patch # User ymh # Date 1498485947 -7200 # Node ID 2a861fed6bded4576bf6aa712be42b71bf96e4ad # Parent dbcee57de2c6017ffacff1dcf5e6f87eaa39a81c Deauthenticate user if refresh was not possible (session expired or total delta reached) diff -r dbcee57de2c6 -r 2a861fed6bde client/src/constants/actionTypes.js --- a/client/src/constants/actionTypes.js Mon Jun 26 15:21:06 2017 +0200 +++ b/client/src/constants/actionTypes.js Mon Jun 26 16:05:47 2017 +0200 @@ -15,6 +15,7 @@ export const AUTH_STORE_TOKEN_ASYNC = 'AUTH_STORE_TOKEN_ASYNC'; export const AUTH_STORE_TOKEN = 'AUTH_STORE_TOKEN'; export const AUTH_LOGOUT = 'AUTH_LOGOUT'; +export const AUTH_DEAUTHENTICATE = 'AUTH_DEAUTHENTICATE'; export const USER_UPDATE_SETTINGS_ASYNC = 'USER_UPDATE_SETTINGS_ASYNC'; export const USER_UPDATE_SETTINGS = 'USER_UPDATE_SETTINGS' diff -r dbcee57de2c6 -r 2a861fed6bde client/src/reducers/authReducer.js --- a/client/src/reducers/authReducer.js Mon Jun 26 15:21:06 2017 +0200 +++ b/client/src/reducers/authReducer.js Mon Jun 26 16:05:47 2017 +0200 @@ -4,6 +4,7 @@ export const isAuthenticated = (state = false, action) => { switch (action.type) { + case types.AUTH_DEAUTHENTICATE: case types.AUTH_LOGOUT: return false; case types.AUTH_LOGIN_SUCCESS: @@ -15,6 +16,7 @@ export const currentUser = (state = null, action) => { switch (action.type) { + case types.AUTH_DEAUTHENTICATE: case types.AUTH_LOGOUT: return null; case types.AUTH_LOGIN_SUCCESS: @@ -31,6 +33,7 @@ export const token = (state = null, action) => { switch (action.type) { + case types.AUTH_DEAUTHENTICATE: case types.AUTH_LOGOUT: return null; case types.AUTH_STORE_TOKEN: diff -r dbcee57de2c6 -r 2a861fed6bde client/src/sagas/networkSaga.js --- a/client/src/sagas/networkSaga.js Mon Jun 26 15:21:06 2017 +0200 +++ b/client/src/sagas/networkSaga.js Mon Jun 26 16:05:47 2017 +0200 @@ -11,7 +11,6 @@ } function pingServer(client, token) { - console.log("PING SERVER", token); if(token) { const timeout = new Promise((resolve, reject) => { setTimeout(reject, config.networkStatusTimeout, 'request timed out'); @@ -39,6 +38,16 @@ // if the error is that there is no token, then we know we have to wait for a login if(error.error && error.error === 'No token in the store') { yield take(types.AUTH_LOGIN_SUCCESS); + } else if (error.non_field_errors && + error.non_field_errors && + error.non_field_errors.length && + error.non_field_errors.length > 0 && + ( error.non_field_errors[0] === 'Signature has expired.' || + error.non_field_errors[0] === 'Refresh has expired.' ) + ) { + yield put({ + type: types.AUTH_DEAUTHENTICATE + }); } } finally { if (yield cancelled()) { diff -r dbcee57de2c6 -r 2a861fed6bde src/.env.tmpl --- a/src/.env.tmpl Mon Jun 26 15:21:06 2017 +0200 +++ b/src/.env.tmpl Mon Jun 26 16:05:47 2017 +0200 @@ -39,3 +39,7 @@ # expiration delta for JWT tokens (in seconds) # default: 3600 # JWT_EXPIRATION_DELTA = 3600 + +# expiration refresh delta for JWT tokens (in seconds) +# default: 3600*24*7 = 604800 +# JWT_REFRESH_EXPIRATION_DELTA = 604800 diff -r dbcee57de2c6 -r 2a861fed6bde src/irinotes/settings.py --- a/src/irinotes/settings.py Mon Jun 26 15:21:06 2017 +0200 +++ b/src/irinotes/settings.py Mon Jun 26 16:05:47 2017 +0200 @@ -236,6 +236,9 @@ 'JWT_ALLOW_REFRESH' : True, 'JWT_EXPIRATION_DELTA' : datetime.timedelta( seconds=config('JWT_EXPIRATION_DELTA', 3600, cast=int) + ), + 'JWT_REFRESH_EXPIRATION_DELTA' : datetime.timedelta( + seconds=config('JWT_REFRESH_EXPIRATION_DELTA', 3600*24*7, cast=int) ) }