Skip to content

Commit

Permalink
Merge pull request #97 from factly/fix/logout
Browse files Browse the repository at this point in the history
add credentials required in logout request
  • Loading branch information
shreeharsha-factly authored Nov 23, 2021
2 parents 9fab178 + eb4524c commit 764edef
Showing 1 changed file with 22 additions and 19 deletions.
41 changes: 22 additions & 19 deletions web/src/components/GlobalNav/AccountMenu.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,25 +23,28 @@ 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);
}

const handleLogout = () => {
fetch(window.REACT_APP_KRATOS_PUBLIC_URL + '/self-service/logout/browser', {
credentials: 'include',
})
.then((res)=>{
window.location.href = res.logout_url
}).catch((err)=>{
.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'
})
})
}
message: 'Error',
description: 'Unable to logout',
});
});
};
return (
<Menu mode="horizontal">
<Menu.SubMenu
Expand All @@ -67,8 +70,8 @@ const AccountMenu = () => {
</Link>
</Menu.Item>
<Menu.Item key="logout" onClick={handleLogout}>
<LogoutOutlined />
Logout
<LogoutOutlined />
Logout
</Menu.Item>
</Menu.SubMenu>
</Menu>
Expand Down

0 comments on commit 764edef

Please sign in to comment.