Skip to content
Merged
Show file tree
Hide file tree
Changes from 28 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
1304d49
feat(astro:actions): add docs for missing public APIs
ArmandPhilippot Oct 20, 2025
2c246b4
replace the error codes list with a link to IANA
ArmandPhilippot Oct 21, 2025
aa3c616
add docs for ActionInputError and an example for ActionError
ArmandPhilippot Oct 21, 2025
415ded6
add description for `actions` and remove `type Actions`
ArmandPhilippot Oct 21, 2025
6e13d8c
add `appendForwardSlash` description
ArmandPhilippot Oct 21, 2025
1999276
remove `astroCalledServerError`
ArmandPhilippot Oct 21, 2025
5b5cd75
remove `callSafely`
ArmandPhilippot Oct 21, 2025
29d1987
add docs for `formDataToObject`
ArmandPhilippot Oct 21, 2025
774e7bf
add `getActionQueryString` and remove `ACTION_QUERY_PARAMS`
ArmandPhilippot Oct 21, 2025
66680e9
add docs for remaining imports
ArmandPhilippot Oct 21, 2025
cbc48cc
remove `ACTION_ERROR_CODES`
ArmandPhilippot Oct 22, 2025
34e86ca
fix broken link
ArmandPhilippot Oct 22, 2025
0007e28
simplify types
ArmandPhilippot Oct 22, 2025
1ec2474
small reorganization
ArmandPhilippot Oct 22, 2025
9f64a4d
add usage example for isActionError
ArmandPhilippot Oct 22, 2025
a64fe8c
reword some existing description to use definition style
ArmandPhilippot Oct 22, 2025
f9d758f
internal linking
ArmandPhilippot Oct 22, 2025
b9506b7
more rewording
ArmandPhilippot Oct 22, 2025
2995b9e
add linking from the Actions guide
ArmandPhilippot Oct 22, 2025
c21e4d8
Merge branch 'main' into feat/add-actions-api-references
ArmandPhilippot Oct 22, 2025
fe5234a
clean up based on Florian feedback
ArmandPhilippot Oct 23, 2025
9524860
add docs for ACTION_QUERY_PARAMS
ArmandPhilippot Oct 23, 2025
12e922f
fix link
ArmandPhilippot Oct 23, 2025
39a16ad
remove a duplicate link
ArmandPhilippot Oct 23, 2025
4559046
Apply Sarah's helpful suggestions + a code snippet fix
ArmandPhilippot Oct 24, 2025
de3b852
add caution regarding falsy values in forms
ArmandPhilippot Oct 24, 2025
b96c617
update `queryString` description and snippet
ArmandPhilippot Oct 24, 2025
ff6622d
Update src/content/docs/en/reference/modules/astro-actions.mdx
florian-lefebvre Oct 27, 2025
d5cc70d
split `accept` property and move its content to the Actions guide
ArmandPhilippot Oct 27, 2025
e74451f
move empty input handling to the guide
ArmandPhilippot Oct 27, 2025
c4165c4
Merge branch 'main' into feat/add-actions-api-references
ArmandPhilippot Oct 27, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/content/docs/en/guides/actions.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ You can use the provided `ActionError` to throw an error from your action `handl

#### Creating an `ActionError`

To throw an error, import the `ActionError()` class from the `astro:actions` module. Pass it a human-readable status `code` (e.g. `"NOT_FOUND"` or `"BAD_REQUEST"`), and an optional `message` to provide further information about the error.
To throw an error, import the [`ActionError()` class](/en/reference/modules/astro-actions/#actionerror) from the `astro:actions` module. Pass it a human-readable status `code` (e.g. `"NOT_FOUND"` or `"BAD_REQUEST"`), and an optional `message` to provide further information about the error.

This example throws an error from a `likePost` action when a user is not logged in, after checking a hypothetical "user-session" cookie for authentication:

Expand Down Expand Up @@ -656,7 +656,7 @@ Actions are accessible as public endpoints based on the name of the action. For

To authorize action requests, add an authentication check to your action handler. You may want to use [an authentication library](/en/guides/authentication/) to handle session management and user information.

Actions expose the full `APIContext` object to access properties passed from middleware using `context.locals`. When a user is not authorized, you can raise an `ActionError` with the `UNAUTHORIZED` code:
Actions expose [a subset of the `APIContext` object](/en/reference/modules/astro-actions/#actionapicontext) to access properties passed from middleware using `context.locals`. When a user is not authorized, you can raise an `ActionError` with the `UNAUTHORIZED` code:

```ts title="src/actions/index.ts" {6-8}
import { defineAction, ActionError } from 'astro:actions';
Expand All @@ -679,7 +679,7 @@ export const server = {

Astro recommends authorizing user sessions from your action handler to respect permission levels and rate-limiting on a per-action basis. However, you can also gate requests to all actions (or a subset of actions) from middleware.

Use the `getActionContext()` function from your middleware to retrieve information about any inbound action requests. This includes the action name and whether that action was called using a client-side remote procedure call (RPC) function (e.g. `actions.blog.like()`) or an HTML form.
Use the [`getActionContext()` function](/en/reference/modules/astro-actions/#getactioncontext) from your middleware to retrieve information about any inbound action requests. This includes the action name and whether that action was called using a client-side remote procedure call (RPC) function (e.g. `actions.blog.like()`) or an HTML form.

The following example rejects all action requests that do not have a valid session token. If the check fails, a "Forbidden" response is returned. Note: this method ensures that actions are only accessible when a session is present, but is _not_ a substitute for secure authorization.

Expand Down
Loading