-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Actions: auto-redirect action response to avoid "confirm form resubmi…
…ssion" dialog (#11603) * feat: redirect with result to avoid resubmission dialog * fix: use standard POST for react forms * fix(test): handle redirect responses * refactor: actionresultbehavior -> disableredirect * refactor: next() -> throw internal error * fix(test): bad referer link * refactor: followRedirect -> followExpectedRedirect * refactor: remove encryption TODO * feat: changeset * chore: whitespace * feat: laravel note * refactor: clean up cookie -> action payload * refactor: actionsinternal -> actionpayload * refactor: use _astroAction const * refactor: actionRedirect string as const * refactor: simplify error check * chore: remove stray console log * refactor: only delete cookies on error * fix: check cookie after handling POST requests * chore: remove unused tgz * Revert "fix: check cookie after handling POST requests" This reverts commit 607f90f. * Revert "refactor: only delete cookies on error" This reverts commit 52aab84.
- Loading branch information
1 parent
685361f
commit f31d466
Showing
9 changed files
with
174 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
--- | ||
'astro': patch | ||
--- | ||
|
||
Improves user experience when render an Action result from a form POST request: | ||
|
||
- Removes "Confirm post resubmission?" dialog when refreshing a result. | ||
- Removes the `?_astroAction=NAME` flag when a result is rendered. | ||
|
||
Also improves the DX of directing to a new route on success. Actions will now redirect to the route specified in your `action` string on success, and redirect back to the previous page on error. This follows the routing convention of established backend frameworks like Laravel. | ||
|
||
For example, say you want to redirect to a `/success` route when `actions.signup` succeeds. You can add `/success` to your `action` string like so: | ||
|
||
```astro | ||
<form method="POST" action={"/success" + actions.signup}> | ||
``` | ||
|
||
- On success, Astro will redirect to `/success`. | ||
- On error, Astro will redirect back to the current page. | ||
|
||
You can retrieve the action result from either page using the `Astro.getActionResult()` function. | ||
|
||
### Note on security | ||
|
||
This uses a temporary cookie to forward the action result to the next page. The cookie will be deleted when that page is rendered. | ||
|
||
⚠ **The action result is not encrypted.** In general, we recommend returning minimal data from an action handler to a) avoid leaking sensitive information, and b) avoid unexpected render issues once the temporary cookie is deleted. For example, a `login` function may return a user's session id to retrieve from your Astro frontmatter, rather than the entire user object. |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters