trails/apps/journal/app/routes/api.settings.passkey.delete.ts
Ullrich Schäfer be5766fa50
Add account settings page with passkey management
- /settings with profile, security, and account sections
- Profile: edit display name and bio
- Security: list passkeys with device labels, add/delete with
  last-passkey warning
- Account: email change with magic link verification, account
  deletion with username confirmation
- Settings link in nav for authenticated users
- E2E tests: auth guard, profile editing, passkey add/delete,
  last-passkey warning, account deletion, nav visibility
- i18n: full en + de translations for all settings UI

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-03-29 10:09:06 +02:00

27 lines
971 B
TypeScript

import { data, redirect } from "react-router";
import { eq, and } from "drizzle-orm";
import type { Route } from "./+types/api.settings.passkey.delete";
import { getSessionUser } from "~/lib/auth.server";
import { getDb } from "~/lib/db";
import { credentials } from "@trails-cool/db/schema/journal";
export async function action({ request }: Route.ActionArgs) {
const user = await getSessionUser(request);
if (!user) throw redirect("/auth/login");
const formData = await request.formData();
const credentialId = formData.get("credentialId") as string;
if (!credentialId) return data({ error: "Missing credential ID" }, { status: 400 });
const db = getDb();
const deleted = await db
.delete(credentials)
.where(and(eq(credentials.id, credentialId), eq(credentials.userId, user.id)))
.returning();
if (deleted.length === 0) {
return data({ error: "Passkey not found" }, { status: 404 });
}
return redirect("/settings#security");
}