Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ Newest first. `Unreleased` is what is on `main` and not yet tagged.

## Unreleased

- **Delete your account from OpenBot Mobile.** Account, then Delete account: type your email address
and "delete my account". The account goes in 14 days, or at once with Delete now, as in the web
app. A sign-in older than ten minutes is asked for again first. Somebody who signs in again before
the account goes sees when it goes and can cancel. An organization that stops the deletion has a
way on from the phone: the only owner of one can delete it there, by typing its name, and an owner
beside others can leave it. The App Store asks that an account can be deleted in the app it can
be made in.
- **OpenBot Mobile follows a change of organization at once.** After you picked another organization
in Account, Chats and the other screens went on showing the one before for up to ten seconds, so an
organization with conversations could read "No chats yet". Every screen now reads again the moment
Expand Down
15 changes: 15 additions & 0 deletions mobile/app/(tabs)/(account)/account.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { router } from "expo-router";
import { useCallback, useEffect, useState } from "react";
import { View } from "react-native";
import { chooseOrganization, organizationChoices } from "../../../src/api";
import { getAccountDeletion } from "../../../src/api/generated/people/people";
import { authClient, serverUrl } from "../../../src/auth";
import {
Icon,
Expand All @@ -18,6 +19,7 @@ import {
IconBuilding,
IconCheck,
IconLogout,
IconTrash,
} from "../../../src/icons";
import {
pushTurnedOn,
Expand Down Expand Up @@ -47,6 +49,10 @@ export default function Account() {
const organizations = useLoad(loadOrganizations, Boolean(session), {
keep: true,
});
// Deleting the account is offered where this OpenBot has it: one that answers where the deletion stands.
// The person's own too, so the line stays while it is read again.
const loadDeletion = useCallback(() => getAccountDeletion(), []);
const deletion = useLoad(loadDeletion, Boolean(session), { keep: true });
async function act(name: string, work: () => Promise<unknown>) {
setBusy(name);
setError("");
Expand Down Expand Up @@ -165,6 +171,15 @@ export default function Account() {
})
}
/>
{deletion.data ? (
<Row
icon={IconTrash}
title="Delete account"
description="Delete your account and everything that's only yours."
tone="danger"
onPress={busy ? undefined : () => router.push("/delete-account")}
/>
) : null}
</Rows>
</ScrollScreen>
);
Expand Down
21 changes: 21 additions & 0 deletions mobile/app/_layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { GestureHandlerRootView } from "react-native-gesture-handler";
import { KeyboardProvider } from "react-native-keyboard-controller";
import { setSignedInPerson } from "../src/api";
import { authClient } from "../src/auth";
import { DeletionGate, useDeletionGate } from "../src/deletion-gate";
import { withSecurityFloor } from "../src/floor-gate";
import { announceGallery } from "../src/gallery/announce";
import { NO_HEADER_LEFT, useHeaderOptions } from "../src/header";
Expand Down Expand Up @@ -96,6 +97,8 @@ function Layout() {
const signedIn = Boolean(session);
// Whether a signed-in person has setting up to finish (the terms, onboarding, their AI): src/setup-gate.tsx.
const setup = useSetupGate(signedIn, session?.user.id);
// Whether the person's account is scheduled to be deleted: then only that is shown (src/deletion-gate.tsx).
const deletion = useDeletionGate(signedIn);
// Once set up, the cards this app draws are announced, as the web app does on load: src/gallery/announce.ts.
const setUp = signedIn && setup.facts !== null && setup.step === null;
useEffect(() => {
Expand Down Expand Up @@ -193,6 +196,22 @@ function Layout() {
name="connections"
options={{ title: "Connections" }}
/>
<Stack.Screen
name="delete-account"
options={{
title: "Delete account",
...SHEET,
sheetAllowedDetents: [SHEET_FULL],
}}
/>
<Stack.Screen
name="delete-organization"
options={{
title: "Delete organization",
...SHEET,
sheetAllowedDetents: [SHEET_FULL],
}}
/>
<Stack.Screen name="connection" options={{ title: "" }} />
{/* Only the way back to an app's screen after its sign-in page: never seen, so no header flashes. */}
<Stack.Screen
Expand Down Expand Up @@ -234,6 +253,8 @@ function Layout() {
</OrbFlightProvider>
{/* Finishing setting up, over the app until it is done; Update OpenBot over that. */}
<SetupGate gate={setup} />
{/* An account scheduled to be deleted: when it goes and how to cancel, over everything but an update. */}
<DeletionGate gate={deletion} />
<VersionGate verdict={verdict} onRetry={() => void check()} />
</View>
);
Expand Down
292 changes: 292 additions & 0 deletions mobile/app/delete-account.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,292 @@
import { router, Stack, useFocusEffect } from "expo-router";
import { Button } from "heroui-native/button";
import { Input } from "heroui-native/input";
import { Label } from "heroui-native/label";
import { TextField } from "heroui-native/text-field";
import { useCallback, useState } from "react";
import { Alert, View } from "react-native";
import {
blockerWayOn,
blockerWords,
DELETE_PHRASE,
DELETION_WAIT_DAYS,
refusalKind,
scheduledSentence,
typedRight,
} from "../src/account-deletion";
import type { AccountDeletionBlocker } from "../src/api/generated/model";
import { removeOrganizationMember } from "../src/api/generated/organizations/organizations";
import {
getAccountDeletion,
requestAccountDeletion,
} from "../src/api/generated/people/people";
import { authClient, signIn } from "../src/auth";
import {
Notice,
Row,
Rows,
Screen,
ScrollScreen,
Section,
SheetTitle,
Text,
} from "../src/components";
import { IconBuilding } from "../src/icons";
import { useLoad } from "../src/use-load";

const TITLE = "Delete account";

/** One line of what is deleted or kept. */
function Line({ children }: { children: string }) {
return (
<View className="flex-row gap-2">
<Text tone="muted">•</Text>
<Text className="flex-1">{children}</Text>
</View>
);
}

/**
* Deleting the person's own account, started here in the app, as the App Store asks of an app people can make
* an account in. The same step as the web app's (Settings, Delete my account), in its words.
*
* The person types their email address and the phrase. The account goes in 14 days, or at once with Delete now.
* OpenBot signs them out everywhere when it takes the request, so the app forgets its sign-in and says when the
* account goes. Signing in again before then shows only that, and a way to cancel (src/deletion-gate.tsx).
*
* OpenBot takes the request only from a sign-in of the last ten minutes. An older one is refused, and Sign in
* again opens the sign-in once more, which makes a new one. An organization the person still has to hand over
* stops the deletion, and each is listed with what to do about it.
*/
export default function DeleteAccount() {
const { data: session } = authClient.useSession();
const loadStanding = useCallback(() => getAccountDeletion(), []);
const standing = useLoad(loadStanding, Boolean(session));
const [typedEmail, setTypedEmail] = useState("");
const [typedPhrase, setTypedPhrase] = useState("");
const [busy, setBusy] = useState<"" | "later" | "now" | "sign-in" | "leave">(
"",
);
const [error, setError] = useState("");
const [signInAgain, setSignInAgain] = useState(false);

// Back from deleting an organization that stopped it: the list is read again, and has one less.
const { refresh: readStanding } = standing;
useFocusEffect(
useCallback(() => {
void readStanding();
}, [readStanding]),
);

const blockers = standing.data?.blockers ?? [];
const ready =
typedRight(session?.user.email, typedEmail, typedPhrase) && !busy;

async function remove(immediate: boolean) {
setBusy(immediate ? "now" : "later");
setError("");
setSignInAgain(false);
try {
const scheduled = await requestAccountDeletion({
confirmEmail: typedEmail.trim(),
confirmPhrase: typedPhrase.trim(),
...(immediate ? { immediate: true } : {}),
});
// OpenBot has ended this sign-in with the request: the phone forgets it, and the sign-in screen is next.
await authClient.signedOutByOpenBot();
Alert.alert(scheduledSentence(scheduled.deleteAfter, immediate));
} catch (failure) {
const kind = refusalKind(failure);
// What stops it is read again, and the list takes the form's place.
if (kind === "blocked") await standing.refresh();
setSignInAgain(kind === "sign-in-again");
setError(
failure instanceof Error
? failure.message
: "Couldn't delete your account. Try again.",
);
} finally {
setBusy("");
}
}

/** What a tap on an organization that stops the deletion does: the way on from it, where the phone has one. */
function wayOn(blocker: AccountDeletionBlocker): (() => void) | undefined {
const way = blockerWayOn(blocker);
if (way === "delete")
return () =>
router.push({
pathname: "/delete-organization",
params: {
id: blocker.organizationId,
name: blocker.organizationName,
},
});
if (way === "leave")
return () =>
Alert.alert(
`Leave ${blocker.organizationName}?`,
"You stop being a member. What you made there stays there.",
[
{ text: "Cancel", style: "cancel" },
{
text: "Leave",
style: "destructive",
onPress: () => void leave(blocker),
},
],
);
return undefined;
}

async function leave(blocker: AccountDeletionBlocker) {
setBusy("leave");
setError("");
try {
await removeOrganizationMember(blocker.organizationId, "me");
await standing.refresh();
} catch (failure) {
setError(
failure instanceof Error
? failure.message
: "Couldn't leave the organization. Try again.",
);
} finally {
setBusy("");
}
}

async function again() {
setBusy("sign-in");
try {
// A new sign-in, though the browser remembers the person: the one OpenBot counts as recent.
if (await signIn({ fresh: true })) {
setError("");
setSignInAgain(false);
}
} catch (failure) {
setError(
failure instanceof Error
? failure.message
: "Sign-in didn't finish. Try again.",
);
} finally {
setBusy("");
}
}

return (
<Screen fade={false}>
<Stack.Screen options={{ title: TITLE }} />
<SheetTitle title={TITLE} />
<ScrollScreen className="gap-5" fade={false}>
<Notice
message={error || standing.error}
action={
signInAgain ? (
<Button
size="sm"
variant="outline"
isDisabled={Boolean(busy)}
onPress={() => void again()}
>
{busy === "sign-in" ? "Opening sign-in…" : "Sign in again"}
</Button>
) : undefined
}
/>
{blockers.length > 0 ? (
// A sentence, not a section's label: a label is one line, and this one doesn't fit one.
<View className="gap-3">
<Text>
Before you can delete your account, sort out these organizations.
</Text>
<Rows>
{blockers.map((blocker) => {
const onPress = wayOn(blocker);
return (
<Row
key={blocker.organizationId}
icon={IconBuilding}
title={blocker.organizationName}
description={blockerWords(blocker)}
chevron={Boolean(onPress)}
onPress={busy ? undefined : onPress}
/>
);
})}
</Rows>
</View>
) : (
<>
<Text>
{`Your account is deleted in ${DELETION_WAIT_DAYS} days. Sign in before then to cancel. Delete now deletes it straight away, and you can't undo it.`}
</Text>
<Section title="Deleted">
<View className="gap-2 px-1">
<Line>
Your conversations, memory, Bots, skills and routines that are
only yours.
</Line>
<Line>Your saved logins, connections and computer.</Line>
</View>
</Section>
<Section title="Kept">
<View className="gap-2 px-1">
<Line>
Messages you sent in organizations you share with others. They
show as from Deleted user.
</Line>
<Line>
Security log entries, for 180 days, without your name or
email.
</Line>
</View>
</Section>
<TextField isRequired>
<Label>Type your email address</Label>
<Input
value={typedEmail}
onChangeText={setTypedEmail}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
keyboardType="email-address"
editable={!busy}
/>
</TextField>
<TextField isRequired>
<Label>{`Type ${DELETE_PHRASE}`}</Label>
<Input
value={typedPhrase}
onChangeText={setTypedPhrase}
autoCapitalize="none"
autoCorrect={false}
autoComplete="off"
editable={!busy}
/>
</TextField>
<View className="gap-2">
<Button
variant="danger"
isDisabled={!ready}
onPress={() => void remove(false)}
>
{busy === "later"
? "Deleting…"
: `Delete in ${DELETION_WAIT_DAYS} days`}
</Button>
<Button
variant="outline"
isDisabled={!ready}
onPress={() => void remove(true)}
>
{busy === "now" ? "Deleting…" : "Delete now"}
</Button>
</View>
</>
)}
</ScrollScreen>
</Screen>
);
}
Loading
Loading