We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 7e3d9da commit 594e8f0Copy full SHA for 594e8f0
1 file changed
src/redux/middleware/authMiddleware.js
@@ -27,8 +27,13 @@ export const storeToken = accessToken => {
27
localStorage.setItem(TOKEN_LOCAL_STORAGE_KEY, accessToken);
28
}
29
30
- // @todo: expire after 'exp' in the token
31
- cookies.set(TOKEN_COOKIES_KEY, accessToken, { expires: 14 }); // expires after 14 days
+ const decodedToken = decode(accessToken);
+ if (decodedToken && isTokenValid(decodedToken)) {
32
+ const expDate = new Date(decodedToken.exp * 1000);
33
+ cookies.set(TOKEN_COOKIES_KEY, accessToken, { expires: expDate }); // expires with token expiration
34
+ } else {
35
+ cookies.erase(TOKEN_COOKIES_KEY);
36
+ }
37
38
};
39
0 commit comments