added automatic logout
All checks were successful
SimcoDash/simcompanies-dashboard/pipeline/head This commit looks good

This commit is contained in:
2020-05-17 00:47:07 +02:00
parent 3bc17e1883
commit 28b3e426d1
2 changed files with 36 additions and 0 deletions

View File

@@ -16,6 +16,21 @@ export default function ChangePassword(props) {
const [statusText, setStatusText] = React.useState(null); const [statusText, setStatusText] = React.useState(null);
const [status, setStatus] = React.useState(null); const [status, setStatus] = React.useState(null);
const logout = async () => {
await fetch(`/simcompanies/API/user/logout`, {
method: 'DELETE',
mode: 'cors',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer'
}).then(
() => { window.location.reload() }
)
}
const postSetPassword = async (url, data) => { const postSetPassword = async (url, data) => {
const response = await fetch(url, { const response = await fetch(url, {
@@ -33,6 +48,9 @@ export default function ChangePassword(props) {
const text = await response.text() const text = await response.text()
await setStatusText(text) await setStatusText(text)
setStatus(response.status) setStatus(response.status)
if (response.status === 200) {
setTimeout(() => { logout() }, 2000)
}
setDisabled(false) setDisabled(false)
setTimeout(() => { setStatus(null) }, 2000) setTimeout(() => { setStatus(null) }, 2000)
} }

View File

@@ -14,6 +14,21 @@ export default function ChangeUsername(props) {
const [statusText, setStatusText] = React.useState(null); const [statusText, setStatusText] = React.useState(null);
const [status, setStatus] = React.useState(null); const [status, setStatus] = React.useState(null);
const logout = async () => {
await fetch(`/simcompanies/API/user/logout`, {
method: 'DELETE',
mode: 'cors',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json'
},
redirect: 'follow',
referrerPolicy: 'no-referrer'
}).then(
() => { window.location.reload() }
)
}
const postSetName = async (url, data) => { const postSetName = async (url, data) => {
const response = await fetch(url, { const response = await fetch(url, {
@@ -31,6 +46,9 @@ export default function ChangeUsername(props) {
const text = await response.text() const text = await response.text()
await setStatusText(text) await setStatusText(text)
setStatus(response.status) setStatus(response.status)
if (response.status === 200) {
setTimeout(() => { logout() }, 2000)
}
setDisabled(false) setDisabled(false)
setTimeout(() => { setStatus(null) }, 2000) setTimeout(() => { setStatus(null) }, 2000)
} }