diff --git a/web/src/components/GlobalNav/AccountMenu.js b/web/src/components/GlobalNav/AccountMenu.js index f7347285..d428882b 100644 --- a/web/src/components/GlobalNav/AccountMenu.js +++ b/web/src/components/GlobalNav/AccountMenu.js @@ -10,6 +10,7 @@ import { Link } from 'react-router-dom'; import { Avatar } from 'antd'; import { useDispatch, useSelector } from 'react-redux'; import { getUserProfile } from '../../actions/profile'; +import { notification } from 'antd'; const AccountMenu = () => { const dispatch = useDispatch(); @@ -22,10 +23,29 @@ const AccountMenu = () => { React.useEffect(() => { dispatch(getUserProfile()); }, [dispatch]); - + + const handleLogout = ()=>{ + fetch(window.REACT_APP_KRATOS_PUBLIC_URL + '/self-service/logout/browser') + .then((res) => { + if (res.status === 200) { + return res.json(); + } else { + throw new Error(res.status); + } + }) + .then((res)=>{ + window.location.href = res.logout_url + }).catch((err)=>{ + notification.error({ + message:'Error', + description:'Unable to login' + }) + }) + } return ( {!loading && profile && profile.medium ? ( @@ -36,21 +56,19 @@ const AccountMenu = () => { } > - + Security - + Profile - - + Logout - diff --git a/web/src/pages/password/index.js b/web/src/pages/password/index.js index 06f7bb71..df59d03a 100644 --- a/web/src/pages/password/index.js +++ b/web/src/pages/password/index.js @@ -30,7 +30,7 @@ function Password() { }) .then((res) => { setUI(res.ui); - if (res.update_successful) { + if (res.state==='success') { notification.success({ message: 'Success', description: 'Password has been successful updated', @@ -48,19 +48,25 @@ function Password() { updatePasswordForm.method = ui.method; updatePasswordForm.style.display = 'none'; + var emailInput = document.createElement('input'); + emailInput.name = 'password_identifier'; + emailInput.value = ui.nodes[1].attributes.value; + var passwordInput = document.createElement('input'); passwordInput.name = 'password'; passwordInput.value = values.password; var csrfInput = document.createElement('input'); csrfInput.name = 'csrf_token'; - csrfInput.value = ui.nodes.find((value) => { - if (value.attributes.name === 'csrf_token') { - return value; - } - }).attributes.value; + csrfInput.value = ui.nodes.find((value) => value.attributes.name === 'csrf_token').attributes.value; + + var methodInput = document.createElement('input'); + methodInput.name = 'method'; + methodInput.value = 'password'; + updatePasswordForm.appendChild(emailInput) updatePasswordForm.appendChild(passwordInput); + updatePasswordForm.appendChild(methodInput); updatePasswordForm.appendChild(csrfInput); document.body.appendChild(updatePasswordForm); updatePasswordForm.submit();