Mercurial > gemma
changeset 1603:2ea2a14f7b25
login token renewal implemented
author | Thomas Junk <thomas.junk@intevation.de> |
---|---|
date | Mon, 17 Dec 2018 15:01:43 +0100 |
parents | e80e35b26f17 |
children | 32a34151d9d7 |
files | client/src/store/user.js |
diffstat | 1 files changed, 15 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/client/src/store/user.js Mon Dec 17 13:01:58 2018 +0100 +++ b/client/src/store/user.js Mon Dec 17 15:01:43 2018 +0100 @@ -14,6 +14,7 @@ */ import { HTTP } from "../lib/http"; +import { toMillisFromString } from "../lib/session"; const init = () => { return { @@ -71,11 +72,21 @@ login({ commit }, user) { // using POST is a bit more secure than GET return new Promise((resolve, reject) => { + const handleResponse = response => { + const { expires } = response.data; + const renew = + (new Date(toMillisFromString(expires)) - new Date()) / 1010; + commit("authSuccess", response.data); + resolve(response); + setTimeout(() => { + HTTP.get("/renew", { + headers: { "X-Gemma-Auth": localStorage.getItem("token") } + }).then(handleResponse); + }, renew); + }; + HTTP.post("/login", user) - .then(response => { - commit("authSuccess", response.data); - resolve(response); - }) + .then(handleResponse) .catch(error => { commit("reset", null, { root: true }); commit("clearAuth");