Implementr form

This commit is contained in:
2025-06-26 13:46:32 +02:00
parent 711fb34021
commit da0524a4fc
12 changed files with 903 additions and 4 deletions

37
src/lib/actions/url.ts Normal file
View File

@@ -0,0 +1,37 @@
"use server"
import { getSession } from "../auth/session"
import { insertUrl } from "../db/urls"
import { urlFormSchema } from "../schema/url"
type Response = {
error: boolean
message: string
}
export async function addUrl(unsafeData: unknown): Promise<Response> {
const { session } = await getSession()
if (!session) {
return {
error: true,
message: "You must be logged in to create a short link."
}
}
const { error, data } = urlFormSchema.safeParse(unsafeData)
if (error) {
return {
error: true,
message: "Error parsing form data."
}
}
await insertUrl(data)
return {
error: false,
message: "Short link created successfully!"
}
}