From 6691ae65db37165fe61fd14ec8047052bf10ccae Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Mon, 5 Sep 2022 11:52:51 -0700 Subject: Option to set token expiration --- modern/src/settings/PreferencesPage.js | 27 +++++++++++++++++++++++---- modern/src/settings/UserPage.js | 1 - 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/modern/src/settings/PreferencesPage.js b/modern/src/settings/PreferencesPage.js index c86d696a..403ea156 100644 --- a/modern/src/settings/PreferencesPage.js +++ b/modern/src/settings/PreferencesPage.js @@ -1,4 +1,5 @@ import React, { useState } from 'react'; +import moment from 'moment'; import { useSelector } from 'react-redux'; import { useNavigate } from 'react-router-dom'; import { @@ -54,7 +55,8 @@ const PreferencesPage = () => { const { languages, language, setLanguage } = useLocalization(); const languageList = Object.entries(languages).map((values) => ({ code: values[0], name: values[1].name })); - const [token, setToken] = useState(); + const [token, setToken] = useState(null); + const [tokenExpiration, setTokenExpiration] = useState(moment().add(1, 'week').locale('en').format(moment.HTML5_FMT.DATE)); const mapStyles = useMapStyles(); const [activeMapStyles, setActiveMapStyles] = usePersistedState('activeMapStyles', ['locationIqStreets', 'osm', 'carto']); @@ -74,9 +76,10 @@ const PreferencesPage = () => { const filter = createFilterOptions(); const generateToken = useCatch(async () => { + const expiration = moment(tokenExpiration, moment.HTML5_FMT.DATE).toISOString(); const response = await fetch('/api/session/token', { method: 'POST', - body: new URLSearchParams(), + body: new URLSearchParams(`expiration=${expiration}`), }); if (response.ok) { setToken(await response.text()); @@ -116,14 +119,30 @@ const PreferencesPage = () => { {languageList.map((it) => {it.name})} + + + + }> + + {t('userToken')} + + + + { + setTokenExpiration(e.target.value); + setToken(null); + }} + /> - {t('userToken')} diff --git a/modern/src/settings/UserPage.js b/modern/src/settings/UserPage.js index 4dc6be95..78b6fcf3 100644 --- a/modern/src/settings/UserPage.js +++ b/modern/src/settings/UserPage.js @@ -259,7 +259,6 @@ const UserPage = () => { - token