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
1 change: 1 addition & 0 deletions .github/workflows/check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ jobs:
run: |
node --import tsx integration/email-otp.ts
node --import tsx integration/native-apple-sign-in.ts
node --import tsx integration/account-deletion.ts
node --import tsx integration/auth-attribution.ts
node --import tsx integration/ads-auth.ts
node --import tsx integration/experiments.ts
Expand Down
6 changes: 6 additions & 0 deletions scheduler/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ For self-hosting and required services, see [../docs/scheduler-app/README.md](..

For production traces, metrics, and correlated logs, see [OBSERVABILITY.md](OBSERVABILITY.md).

## Account deletion requests

An authenticated user can request deletion from **Account settings** in iOS. An operator with the application administrator role can process a verified request at `/admin/account-deletion`. New requests should be checked regularly and verified requests are normally completed within 30 days. The shared App Review account can exercise the request and cancellation steps without entering the operator queue.

Completing a request cancels billing, revokes any Sign in with Apple authorization, erases account records, and queues owned uploads for storage cleanup. Workspaces the user still owns close. The user can transfer a shared workspace before deletion to retain its data and membership. Retry a request from the queue after an upstream failure. The row stays available until the user’s completion email has been sent.

## Development

From the repository root (Node.js 20.9+ and Yarn 4.9.2):
Expand Down
106 changes: 106 additions & 0 deletions scheduler/app/admin/account-deletion/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { headers } from "next/headers";
import Link from "next/link";
import { notFound, redirect } from "next/navigation";

import { LoginForm } from "@/components/login-form";
import { Button } from "@/components/ui/button";
import { processAccountDeletion } from "@/lib/auth/account-deletion";
import { auth } from "@/lib/auth/auth";
import { DEMO_LOGIN_EMAIL } from "@/lib/auth/test-users";
import { prisma } from "@/lib/prisma";

export const dynamic = "force-dynamic";
const path = "/admin/account-deletion";

async function operatorSession() {
const session = await auth.api.getSession({ headers: await headers() });
if (!session) return null;
const operator = await prisma.user.findUnique({ where: { id: session.user.id }, select: { isAdmin: true } });
if (!operator?.isAdmin) notFound();
return session;
}

async function processRequest(form: FormData) {
"use server";
if (!(await operatorSession())) redirect(path);
const id = form.get("id");
if (typeof id !== "string" || !/^c[a-z0-9]{20,35}$/.test(id) || form.get("confirm") !== "checked") redirect(path);
try {
await processAccountDeletion(id);
} catch {
redirect(`${path}?id=${id}&result=retry`);
}
redirect(`${path}?result=complete`);
}

export default async function AccountDeletionQueue({
searchParams,
}: {
searchParams: Promise<{ id?: string; result?: string }>;
}) {
if (!(await operatorSession())) return <LoginForm callbackURL={path} />;
const { id, result } = await searchParams;
const pending = await prisma.accountDeletionRequest.findMany({
where: {
completedAt: null,
OR: [{ user: { email: { not: DEMO_LOGIN_EMAIL, mode: "insensitive" } } }, { purgedAt: { not: null } }],
},
select: {
id: true,
requestedAt: true,
startedAt: true,
purgedAt: true,
user: { select: { email: true, _count: { select: { ownedWorkspaces: true } } } },
},
orderBy: { requestedAt: "asc" },
take: 100,
});
const selected = id ? pending.find((item) => item.id === id) : undefined;

return (
<main className="mx-auto max-w-3xl space-y-6 p-8">
<h1 className="text-3xl font-semibold">Account deletion requests</h1>
{result === "complete" && <p role="status">Deletion completed.</p>}
{result === "retry" && (
<p role="alert">The request still needs attention. Check for an active publishing run and retry.</p>
)}
{selected ? (
<form action={processRequest} className="space-y-4 rounded-lg border p-4">
<input type="hidden" name="id" value={selected.id} />
<p>{selected.user?.email ?? "Account already deleted"}</p>
{selected.purgedAt ? (
<p>Retry delivery of the completion email.</p>
) : (
<p>
Processing cancels any active subscription and permanently deletes the account, its data, and its
remaining owned workspaces ({selected.user?._count.ownedWorkspaces ?? 0}).
</p>
)}
<label className="flex items-center gap-2">
<input type="checkbox" required name="confirm" value="checked" />
I’ve confirmed this is the request to process.
</label>
<Button type="submit" variant="destructive">
{selected.purgedAt ? "Send confirmation" : "Complete deletion"}
</Button>
<Link className="ms-4 underline" href={path}>
Back to requests
</Link>
</form>
) : pending.length === 0 ? (
<p>No pending requests.</p>
) : (
<ul className="divide-y">
{pending.map((request) => (
<li key={request.id} className="py-3">
<Link className="underline" href={`${path}?id=${request.id}`}>
{request.user?.email ?? "Confirmation pending"} · {request.requestedAt.toISOString().slice(0, 10)}
{request.startedAt && !request.purgedAt && " · Started"}
</Link>
</li>
))}
</ul>
)}
</main>
);
}
53 changes: 53 additions & 0 deletions scheduler/app/api/v1/account-deletion/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { type NextRequest, NextResponse } from "next/server";

import { requireBrowserSession } from "@/lib/middleware/auth";
import { hasAllowedOrigin } from "@/lib/middleware/origin";
import { prisma } from "@/lib/prisma";
import { BadRequestError, ForbiddenError, handleApiError } from "@/lib/utils/errors";

export const dynamic = "force-dynamic";
const headers = { "Cache-Control": "private, no-store" };

async function status(userId: string) {
const [request, ownedWorkspaces] = await Promise.all([
prisma.accountDeletionRequest.findUnique({
where: { userId },
select: { requestedAt: true, startedAt: true },
}),
prisma.teamWorkspace.count({ where: { creatorId: userId } }),
]);
return NextResponse.json({ request, ownedWorkspaces }, { headers });
}

export async function GET(req: NextRequest) {
try {
const { user } = await requireBrowserSession(req);
return await status(user.id);
} catch (error) {
return handleApiError(error, req);
}
}

export async function POST(req: NextRequest) {
try {
if (!hasAllowedOrigin(req)) throw new ForbiddenError();
const { user } = await requireBrowserSession(req);
const body = await req.json().catch(() => null);
if (body?.confirmed !== true) throw new BadRequestError("Confirm that you want to delete your account.");
await prisma.accountDeletionRequest.createMany({ data: [{ userId: user.id }], skipDuplicates: true });
return await status(user.id);
} catch (error) {
return handleApiError(error, req);
}
}

export async function DELETE(req: NextRequest) {
try {
if (!hasAllowedOrigin(req)) throw new ForbiddenError();
const { user } = await requireBrowserSession(req);
await prisma.accountDeletionRequest.deleteMany({ where: { userId: user.id, startedAt: null } });
return await status(user.id);
} catch (error) {
return handleApiError(error, req);
}
}
10 changes: 8 additions & 2 deletions scheduler/app/deletion/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,9 +134,16 @@ export default async function DataDeletionPage() {
}}
/>
</h4>
<p className="text-muted-foreground ms-8">
{copy(
"In the SimplePost iOS app, open Account settings and choose Delete account. Review what will be deleted, then confirm your request. You can cancel from the same screen before processing begins.",
)}
</p>
<p className="text-muted-foreground ms-8">
<UiCopy
source="Account deletion is currently handled as a verified support request. Send an email from your registered SimplePost address to <part1></part1>:"
source={
'If you cannot use the iOS app, send an email from your registered SimplePost address to <part1></part1> with the subject "Data Deletion Request". We may ask you to verify account ownership.'
}
components={{
part1: (
<a href="mailto:support@simplepost.social" className="text-primary hover:underline font-medium">
Expand All @@ -147,7 +154,6 @@ export default async function DataDeletionPage() {
/>
</p>
<ol className="list-decimal list-inside text-muted-foreground space-y-2 ms-8">
<li>{copy('Use the subject line "Data Deletion Request"')}</li>
<li>{copy("State that you want your SimplePost account and associated data deleted")}</li>
<li>{copy("Include the email address used for your SimplePost account")}</li>
<li>{copy("Complete any identity verification requested by support")}</li>
Expand Down
5 changes: 5 additions & 0 deletions scheduler/app/privacy/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,11 @@ export default async function PrivacyPage() {
components={{ part1: <a className="underline" href="https://openai.com/policies/privacy-policy/" /> }}
/>
</p>
<p className="text-muted-foreground leading-relaxed mb-4">
{copy(
"We disable this sharing for accounts used in the SimplePost iOS app. This also applies when you later use the same account on the web.",
)}
</p>
<AdsMeasurementWithdrawal />
<p className="text-muted-foreground leading-relaxed">
{copy(
Expand Down
Loading
Loading