Skip to content

Commit

Permalink
Log out if user deletes their own account #2672
Browse files Browse the repository at this point in the history
  • Loading branch information
iamleeg committed May 26, 2022
1 parent c5f7d8b commit 996db5c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions verification/curator-service/ui/src/components/User.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export default interface User {
_id: string;
id?: string; // session user has id, not _id
name?: string | null;
email: string;
roles: string[];
Expand Down
11 changes: 11 additions & 0 deletions verification/curator-service/ui/src/components/Users.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ const rowMenuStyles = makeStyles((theme: Theme) => ({
}));

function RowMenu(props: {
myId: string;
rowId: string;
rowData: TableRow;
setError: (error: string) => void;
Expand Down Expand Up @@ -139,6 +140,15 @@ function RowMenu(props: {
props.setError('');
const deleteUrl = '/api/users/' + props.rowId;
await axios.delete(deleteUrl);
if (props.rowId === props.myId) {
/* The user has deleted themselves (alright metaphysicists, their own account).
* We need to redirect them to the homepage, because they can't use the app any more.
* But we also need to end their session, to avoid errors looking up their user.
* When the app can't deserialise the (now-nonexistent) user from the session, it will
* log them out and display the sign up page again.
*/
window.location.replace('/');
}
props.refreshData();
} catch (e) {
props.setError((e as Error).toString());
Expand Down Expand Up @@ -270,6 +280,7 @@ class Users extends React.Component<Props, UsersState> {
rowData: TableRow,
): JSX.Element => (
<RowMenu
myId={this.props.user?.id ?? ''}
rowId={rowData.id}
rowData={rowData}
refreshData={(): void =>
Expand Down

0 comments on commit 996db5c

Please sign in to comment.