Nicholai a0dd50f59b
feat(auth): add user profiles and improve auth security (#33)
- Wire up real user data to sidebar, header, and account modal
- Add functional profile editing (first name, last name) via WorkOS API
- Add password change functionality via WorkOS API
- Add logout functionality to sidebar and header dropdowns
- Migrate from manual WorkOS SDK to @workos-inc/authkit-nextjs
- Add server-side input validation with Zod schemas for all auth routes
- Add shared validation schemas for auth, users, teams, schedule, financial
- Fix 30-second auto-logout by properly handling refresh tokens
- Add SidebarUser type and toSidebarUser helper for UI components
- Add getInitials utility for avatar fallbacks
- Document rate limiting configuration for Cloudflare WAF
- Fix login page Suspense boundary for Next.js 15 compatibility
- Remove obsolete workos-client.ts in favor of authkit helpers

Co-authored-by: Nicholai <nicholaivogelfilms@gmail.com>
2026-02-05 08:20:51 -07:00

54 lines
1.5 KiB
TypeScript
Executable File

import { NextRequest, NextResponse } from "next/server"
import { getWorkOS } from "@workos-inc/authkit-nextjs"
import { z } from "zod"
const passwordResetSchema = z.object({
email: z.string().email("Please enter a valid email address"),
})
export async function POST(request: NextRequest) {
try {
// validate input
const body = await request.json()
const parseResult = passwordResetSchema.safeParse(body)
if (!parseResult.success) {
// still return success to prevent email enumeration
return NextResponse.json({
success: true,
message: "If an account exists, a reset link has been sent",
})
}
const { email } = parseResult.data
// check if workos is configured
const isConfigured =
process.env.WORKOS_API_KEY &&
process.env.WORKOS_CLIENT_ID &&
!process.env.WORKOS_API_KEY.includes("placeholder")
if (!isConfigured) {
return NextResponse.json({
success: true,
message: "Password reset link sent (dev mode)",
})
}
const workos = getWorkOS()
await workos.userManagement.createPasswordReset({ email })
return NextResponse.json({
success: true,
message: "If an account exists, a reset link has been sent",
})
} catch (error) {
console.error("Password reset error:", error)
// always return success to prevent email enumeration
return NextResponse.json({
success: true,
message: "If an account exists, a reset link has been sent",
})
}
}