Sample User Deletion Page
This is a sample page that displays a user deletion confirmation page with GET /users/[id]/delete
and deletes the user with POST /users/[id]/delete
.
---import { formFor } from "accel-web";import Layout from "src/layouts/Layout.astro";import { User } from "src/models";
// Retrieve the user by id// If the user does not exist, a RecordNotFound error is thrown and a 404 page is displayedconst user = User.find(Astro.params.id);
if (Astro.request.method === "POST") { user.destroy(); return Astro.redirect("/users");}const f = formFor(user);const { Form, Submit } = f;---
<Layout> <h2>Delete User</h2> <Form method="post"> <div> <b>{user.email}</b> will be deleted. Are you sure? </div> <div> <Submit>Delete</Submit> <a href="/users">Cancel</a> </div> </Form></Layout>