Skip to content

Commit

Permalink
add credentials required in logout request
Browse files Browse the repository at this point in the history
  • Loading branch information
shreeharsha-factly committed Nov 23, 2021
1 parent 9fab178 commit eb4524c
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 eb4524c

Please sign in to comment.