Files
CatoandClaude Opus 5.5 6dcae92a78 fix(auth): a deleted account takes its documents, bots and conversations (#292)
* fix(auth): a deleted account takes its documents, bots and conversations

When people were GoTrue users, deleting the auth.users row cascaded through
every botsmann table. Since accounts are AccountKit's (#289), deleting an
account in the account panel removed the account and left the person's
documents, chunks, bots, conversations, context, settings and profile
behind, under an id nobody holds. onAccountDeleted now removes them, and
the person's uploaded files in the documents bucket.

A test reads the migrations and fails when a table that referenced
auth.users is missing from PERSON_ROWS.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* ci(auth): a navigation sent on after landing is not a failed journey

The settings page can send a just-signed-in browser on once more while its
session loads; Playwright reports the first navigation as aborted. The
journey now waits for the page to arrive, however it gets there.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

* fix(auth): ask the server before sending a signed-in visitor to sign in

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_019MDtmuJhiHPASaR5k8raL9

---------

Co-authored-by: Claude <noreply@anthropic.com>
2026-11-02 23:51:09 +01:00

26 lines
1.3 KiB
TypeScript

import 'server-only';
import { createAuthMailer } from '@bitbaum/accountkit/auth/mail';
import { createAuthRuntime } from '@bitbaum/accountkit/auth/next';
import { signInMethods } from '@bitbaum/accountkit/auth';
import { getDb } from '@/lib/db';
import { removePersonData } from './deletion';
import { authSite, botsmannAuthOptions } from './options';
/**
* Accounts for Botsmann: @bitbaum/accountkit, the same account system as
* every fleet product. Email and password, an emailed sign-in link, passkeys,
* a second factor, recovery, "Continue with OrangeCat" and the shared sign-in,
* each offered only when its env is set. AccountKit is the only credential
* writer; OrangeCat's GoTrue is no longer asked who anyone is.
*/
export const authMail = createAuthMailer({ site: authSite() });
export const mailConfigured = () => authMail.configured;
export const methods = () => signInMethods(process.env, mailConfigured());
export const { GET, POST, getSession, sessionFor, authStatus, getAuth } = createAuthRuntime({
...botsmannAuthOptions({ mail: authMail, getDatabase: () => getDb() }),
// A deleted account takes its documents, bots, conversations and settings
// with it, as deleting the auth.users row used to.
onAccountDeleted: ({ userId }) => removePersonData(userId),
});