From f649d2120713ea3b6c3e783b0eb25e7846565b88 Mon Sep 17 00:00:00 2001 From: Graham Lee Date: Wed, 25 May 2022 16:07:54 +0100 Subject: [PATCH] Log out if user deletes their own account #2672 --- .../curator-service/ui/src/components/User.tsx | 1 + .../curator-service/ui/src/components/Users.tsx | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/verification/curator-service/ui/src/components/User.tsx b/verification/curator-service/ui/src/components/User.tsx index 42aeef7b5..ec5c2eee5 100644 --- a/verification/curator-service/ui/src/components/User.tsx +++ b/verification/curator-service/ui/src/components/User.tsx @@ -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[]; diff --git a/verification/curator-service/ui/src/components/Users.tsx b/verification/curator-service/ui/src/components/Users.tsx index 7281e31c1..7626e0e10 100644 --- a/verification/curator-service/ui/src/components/Users.tsx +++ b/verification/curator-service/ui/src/components/Users.tsx @@ -97,6 +97,7 @@ const rowMenuStyles = makeStyles((theme: Theme) => ({ })); function RowMenu(props: { + myId: string; rowId: string; rowData: TableRow; setError: (error: string) => void; @@ -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()); @@ -270,6 +280,7 @@ class Users extends React.Component { rowData: TableRow, ): JSX.Element => (