From 064e6db7009afb57e817b7ba00e25fcf9db15860 Mon Sep 17 00:00:00 2001 From: "Allan K. Koech" Date: Wed, 11 Nov 2026 01:40:24 +0300 Subject: [PATCH 1/2] feat: added password reset action for auth users --- README.md | 1 + components/database/table-detail-view.tsx | 45 ++++++- .../database/table-records-docs-drawer.tsx | 26 ++++ openapi.yaml | 127 ++++++++++++++++++ package-lock.json | 4 +- package.json | 2 +- 6 files changed, 201 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index f7ae0b6..953edd7 100644 --- a/README.md +++ b/README.md @@ -151,6 +151,7 @@ For entities with `type: "auth"`: - Per-user “Create API Key” from row actions - **Login methods** — `auth.password` / `auth.otp` / `auth.oauth` on the schema (defaults: password on, OTP/OAuth off). Public apps read `GET /api/v1/auth/{entity}/methods`. - **Email verification** — `auth.requireEmailVerification` (default off). Auth records include system field `email_verified` (admin-editable). Apps use `/verify-email` and `/verify-email/request`. +- **Password reset** — auth row actions can send a reset email via `/password-reset/request`. Users complete the flow with `/password-reset` (HTML form or JSON `{ token, password }`). - **OAuth providers** — shown under Auth only when `auth.oauth` is on; per-provider enablement via `enabled_for_entity` Auth / OAuth workflow: diff --git a/components/database/table-detail-view.tsx b/components/database/table-detail-view.tsx index 3a9f1e6..7fcd89a 100644 --- a/components/database/table-detail-view.tsx +++ b/components/database/table-detail-view.tsx @@ -1,7 +1,7 @@ "use client" import * as React from "react" -import { RefreshCw, Cog, FileText, Trash2, Search, Plus, Key, Mail, MoreHorizontal } from "lucide-react" +import { RefreshCw, Cog, FileText, Trash2, Search, Plus, Key, KeyRound, Mail, MoreHorizontal } from "lucide-react" import { Badge } from "@/components/ui/badge" import { Button } from "@/components/ui/button" @@ -265,6 +265,45 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate, onTab } } + const handleSendPasswordResetEmail = async (row: { email?: string }) => { + const email = typeof row.email === "string" ? row.email.trim() : "" + if (!email) { + toast({ + variant: "destructive", + title: "Email required", + description: "This user has no email address.", + }) + return + } + + try { + const response = await apiClient.call( + `/api/v1/auth/${encodeURIComponent(table.schema.name)}/password-reset/request`, + { + method: "POST", + body: JSON.stringify({ email }), + }, + ) + const error = getApiClientError(response) + if (error) { + throw new Error(error) + } + + toast({ + title: "Password Reset Email Requested", + description: "If an account exists for that email, we sent a password reset link.", + duration: 4000, + }) + } catch (error) { + console.error("Failed to send password reset email:", error) + toast({ + variant: "destructive", + title: "Could not send password reset", + description: error instanceof Error ? error.message : "Failed to send password reset email.", + }) + } + } + const handleCreateApiKeyForUser = (userId: string) => { openCreateApiKeyDialog(setCreateApiKeyForUserId, setCreateApiKeyRequested, userId) setActiveTab("api-keys") @@ -438,6 +477,10 @@ export function TableDetailView({ table, onBack, apiClient, onTableUpdate, onTab Send verification email + handleSendPasswordResetEmail(row)}> + + Reset password + diff --git a/components/database/table-records-docs-drawer.tsx b/components/database/table-records-docs-drawer.tsx index 74260ce..dc989be 100644 --- a/components/database/table-records-docs-drawer.tsx +++ b/components/database/table-records-docs-drawer.tsx @@ -224,6 +224,32 @@ function AuthDocsSection({ entityName }: { entityName: string }) { errors={[{ code: "400", message: "Invalid or expired verification link" }]} /> + + + + Date: Wed, 11 Nov 2026 01:48:10 +0300 Subject: [PATCH 2/2] fixes rehydration of table drawer on schema changes --- components/database/table-config-drawer.tsx | 155 +++++++++++--------- 1 file changed, 84 insertions(+), 71 deletions(-) diff --git a/components/database/table-config-drawer.tsx b/components/database/table-config-drawer.tsx index 9ef977a..56cc4ad 100644 --- a/components/database/table-config-drawer.tsx +++ b/components/database/table-config-drawer.tsx @@ -76,6 +76,32 @@ interface TableConfigDrawerProps { } */ +function transformFieldsForEditor(fields: TableMetadata["schema"]["fields"] | undefined) { + return ( + fields?.map((col) => { + const normalized = normalizeFieldTypeForEditor(col) + return { + ...col, + type: normalized.type, + precision: normalized.precision, + old_name: col.name, + // Flatten constraints for UI + primaryKey: col.primary_key || false, + minValue: col.constraints?.min_value || null, + maxValue: col.constraints?.max_value || null, + defaultValue: col.constraints?.default_value || null, + validator: col.constraints?.validator || null, + foreign_key: col.foreign_key, + } + }) || [] + ) +} + +function normalizeRuleMode(mode: string | undefined) { + // Convert empty string to "admin" for UI (Select doesn't allow empty string values) + return mode === "" || !mode ? "admin" : mode +} + // NOTE: We don't support changing of field names yet! export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpdate, onTablesUpdate, tables = [] }: TableConfigDrawerProps) { const [columns, setColumns] = React.useState([]) @@ -103,6 +129,7 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda normalizeAuthMethods(table.schema.auth), ) const [savingAuthMethod, setSavingAuthMethod] = React.useState(null) + const wasOpenRef = React.useRef(false) const { toast } = useToast() const navigate = useNavigate() const isAuthEntity = table.schema.type === "auth" @@ -110,82 +137,66 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda // Get unique key for field (use id if exists, otherwise generate one) const getFieldKey = (field: any, index: number) => field.id || `temp-${index}` + // Only hydrate drawer state when it opens. Parent table updates (auth toggles, + // schema saves) must not reset the active tab or feel like a close/reopen. React.useEffect(() => { - if (open) { - // Transform API format (with constraints) to UI format (flat camelCase) - const transformedColumns = table.schema?.fields.map(col => { - const normalized = normalizeFieldTypeForEditor(col) - return { - ...col, - type: normalized.type, - precision: normalized.precision, - old_name: col.name, - // Flatten constraints for UI - primaryKey: col.primary_key || false, - minValue: col.constraints?.min_value || null, - maxValue: col.constraints?.max_value || null, - defaultValue: col.constraints?.default_value || null, - validator: col.constraints?.validator || null, - // Include foreign_key if present - foreign_key: col.foreign_key, + const justOpened = open && !wasOpenRef.current + wasOpenRef.current = open + if (!justOpened) { + return + } + + setColumns(transformFieldsForEditor(table.schema?.fields)) + setRules({ + list: { + mode: normalizeRuleMode(table.schema.rules?.list?.mode), + expr: table.schema.rules?.list?.expr || "", + }, + get: { + mode: normalizeRuleMode(table.schema.rules?.get?.mode), + expr: table.schema.rules?.get?.expr || "", + }, + add: { + mode: normalizeRuleMode(table.schema.rules?.add?.mode), + expr: table.schema.rules?.add?.expr || "", + }, + update: { + mode: normalizeRuleMode(table.schema.rules?.update?.mode), + expr: table.schema.rules?.update?.expr || "", + }, + delete: { + mode: normalizeRuleMode(table.schema.rules?.delete?.mode), + expr: table.schema.rules?.delete?.expr || "", + }, + }) + setAuthMethods(normalizeAuthMethods(table.schema.auth)) + setActiveTab("schema") + setHasUnsavedChanges(false) + setExpandedFields(new Set()) + setDeletedColumns([]) + + void (async () => { + try { + const fresh = await apiClient.call(`/api/v1/schemas/${table.schema.name}`) + if ((fresh as { error?: unknown[] })?.error?.length) { + return + } + if (!schemaFieldsNeedMigration(fresh.schema?.fields ?? [])) { + return } - }) || [] - setColumns(transformedColumns) - // Initialize rules with mode and expr from API - // Convert empty string to "admin" for UI (Select doesn't allow empty string values) - const normalizeMode = (mode: string | undefined) => { - return mode === "" || !mode ? "admin" : mode - } - setRules({ - list: { - mode: normalizeMode(table.schema.rules?.list?.mode), - expr: table.schema.rules?.list?.expr || "", - }, - get: { - mode: normalizeMode(table.schema.rules?.get?.mode), - expr: table.schema.rules?.get?.expr || "", - }, - add: { - mode: normalizeMode(table.schema.rules?.add?.mode), - expr: table.schema.rules?.add?.expr || "", - }, - update: { - mode: normalizeMode(table.schema.rules?.update?.mode), - expr: table.schema.rules?.update?.expr || "", - }, - delete: { - mode: normalizeMode(table.schema.rules?.delete?.mode), - expr: table.schema.rules?.delete?.expr || "", - }, - }) - setAuthMethods(normalizeAuthMethods(table.schema.auth)) - setActiveTab("schema") - setHasUnsavedChanges(false) - setExpandedFields(new Set()) - setDeletedColumns([]) - void (async () => { - try { - const fresh = await apiClient.call(`/api/v1/schemas/${table.schema.name}`) - if ((fresh as { error?: unknown[] })?.error?.length) { - return - } - if (!schemaFieldsNeedMigration(fresh.schema?.fields ?? [])) { - return - } - - const migrated = await migrateSchemaFieldsIfNeeded(apiClient, fresh) - if (migrated) { - onTableUpdate(migrated) - } else { - setHasUnsavedChanges(true) - } - } catch (error) { - console.error("Failed to migrate legacy field types:", error) + const migrated = await migrateSchemaFieldsIfNeeded(apiClient, fresh) + if (migrated) { + setColumns(transformFieldsForEditor(migrated.schema?.fields)) + onTableUpdate(migrated) + } else { setHasUnsavedChanges(true) } - })() - } + } catch (error) { + console.error("Failed to migrate legacy field types:", error) + setHasUnsavedChanges(true) + } + })() }, [open, table, apiClient, onTableUpdate]) const addColumn = () => { @@ -346,6 +357,8 @@ export function TableConfigDrawer({ table, apiClient, open, onClose, onTableUpda if ((updatedTable as any)?.error?.length > 0) throw (updatedTable as any).error onTableUpdate(updatedTable) + setColumns(transformFieldsForEditor(updatedTable.schema?.fields)) + setDeletedColumns([]) setHasUnsavedChanges(false) toast({ title: "Table Updated",