feat: added password reset action for auth users

This commit is contained in:
2026-11-11 01:40:24 +03:00
parent c3b1da50d2
commit 064e6db700
6 changed files with 201 additions and 4 deletions

View File

@@ -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:

View File

@@ -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
<Mail className="mr-2 h-4 w-4" />
Send verification email
</DropdownMenuItem>
<DropdownMenuItem onClick={() => handleSendPasswordResetEmail(row)}>
<KeyRound className="mr-2 h-4 w-4" />
Reset password
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
</TableCell>

View File

@@ -224,6 +224,32 @@ function AuthDocsSection({ entityName }: { entityName: string }) {
errors={[{ code: "400", message: "Invalid or expired verification link" }]}
/>
<SimpleEndpointDoc
method="POST"
endpoint={`${authPrefix}/password-reset/request`}
description="Email a password reset link. Always returns sent:true (including unknown addresses). Needs SMTP and siteDomain. Link expires in 1 hour."
requestExample={`curl -X POST "${baseUrl}${authPrefix}/password-reset/request" \\
-H "Content-Type: application/json" \\
-d '{ "email": "user@example.com" }'`}
responseExample={JSON.stringify({ status: 200, data: { sent: true }, error: "" }, null, 2)}
errors={[
{ code: "400", message: "Invalid email, SMTP missing, or siteDomain unset" },
{ code: "429", message: "Rate limited" },
{ code: "502", message: "Failed to send the password reset email" },
]}
/>
<SimpleEndpointDoc
method="POST"
endpoint={`${authPrefix}/password-reset`}
description="Set a new password with the token from the email link. GET with ?token= shows an HTML form."
requestExample={`curl -X POST "${baseUrl}${authPrefix}/password-reset" \\
-H "Content-Type: application/json" \\
-d '{ "token": "reset_token_from_link", "password": "new-secure-password" }'`}
responseExample={JSON.stringify({ status: 200, data: { reset: true }, error: "" }, null, 2)}
errors={[{ code: "400", message: "Invalid/expired link or weak password" }]}
/>
<SimpleEndpointDoc
method="POST"
endpoint={`${authPrefix}/otp/request`}

View File

@@ -403,6 +403,133 @@ paths:
"500":
$ref: "#/components/responses/InternalError"
/auth/{entity_name}/password-reset/request:
post:
tags: [Auth]
summary: Email a password reset link
description: |
Always returns `{ "sent": true }` for unknown addresses (no enumeration).
Requires SMTP and `siteDomain`. Link expires in 1 hour. Rate-limited like OTP
(5/min per IP; 3 emails/hour per recipient).
security: []
parameters:
- $ref: "#/components/parameters/EntityName"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [email]
properties:
email:
type: string
format: email
responses:
"200":
description: Request accepted
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/ApiEnvelope"
- type: object
properties:
data:
type: object
properties:
sent:
type: boolean
example: true
"400":
description: Invalid email, SMTP missing, or siteDomain unset
content:
application/json:
schema:
$ref: "#/components/schemas/ApiEnvelope"
"429":
$ref: "#/components/responses/TooManyRequests"
"502":
description: Failed to send the password reset email
content:
application/json:
schema:
$ref: "#/components/schemas/ApiEnvelope"
"500":
$ref: "#/components/responses/InternalError"
/auth/{entity_name}/password-reset:
get:
tags: [Auth]
summary: Password reset form (HTML)
description: |
Opens from the reset email link (`?token=`). Shows a form to choose a new password.
Token lasts 1 hour and is single-use.
security: []
parameters:
- $ref: "#/components/parameters/EntityName"
- name: token
in: query
required: true
schema:
type: string
responses:
"200":
description: HTML password reset form
content:
text/html:
schema:
type: string
"400":
description: Missing token
post:
tags: [Auth]
summary: Reset password with token (JSON)
description: |
App-owned or form submit flow. Body contains the token from the email link and the new password
(min 8 characters, no whitespace). Existing sessions for the account are invalidated.
security: []
parameters:
- $ref: "#/components/parameters/EntityName"
requestBody:
required: true
content:
application/json:
schema:
type: object
required: [token, password]
properties:
token:
type: string
password:
type: string
format: password
minLength: 8
responses:
"200":
description: Password updated
content:
application/json:
schema:
allOf:
- $ref: "#/components/schemas/ApiEnvelope"
- type: object
properties:
data:
type: object
properties:
reset:
type: boolean
example: true
"400":
description: Invalid/expired link or weak password
content:
application/json:
schema:
$ref: "#/components/schemas/ApiEnvelope"
"500":
$ref: "#/components/responses/InternalError"
/auth/{entity_name}/refresh:
post:
tags: [Auth]

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "mantisbase-admin",
"version": "0.4.2",
"version": "0.4.3",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "mantisbase-admin",
"version": "0.4.2",
"version": "0.4.3",
"dependencies": {
"@hookform/resolvers": "^3.9.1",
"@radix-ui/react-accordion": "1.2.2",

View File

@@ -1,6 +1,6 @@
{
"name": "mantisbase-admin",
"version": "0.4.2",
"version": "0.4.3",
"private": true,
"scripts": {
"export": "next build && next export",