mirror of
https://github.com/withastro/astro.git
synced 2025-03-24 23:21:57 -05:00
fix: check cookie after handling POST requests
This commit is contained in:
parent
52aab84b6b
commit
607f90f07b
1 changed files with 8 additions and 8 deletions
|
@ -30,14 +30,6 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
// so short circuit if already defined.
|
||||
if (locals._actionPayload) return next();
|
||||
|
||||
const actionPayload = context.cookies.get(ACTION_QUERY_PARAMS.actionPayload)?.json();
|
||||
if (actionPayload) {
|
||||
if (!isActionPayload(actionPayload)) {
|
||||
throw new Error('Internal: Invalid action payload in cookie.');
|
||||
}
|
||||
return renderResult({ context, next, ...actionPayload });
|
||||
}
|
||||
|
||||
// Heuristic: If body is null, Astro might've reset this for prerendering.
|
||||
if (import.meta.env.DEV && request.method === 'POST' && request.body === null) {
|
||||
// eslint-disable-next-line no-console
|
||||
|
@ -58,6 +50,14 @@ export const onRequest = defineMiddleware(async (context, next) => {
|
|||
return handlePostLegacy({ context, next });
|
||||
}
|
||||
|
||||
const actionPayload = context.cookies.get(ACTION_QUERY_PARAMS.actionPayload)?.json();
|
||||
if (context.request.method === 'GET' && actionPayload) {
|
||||
if (!isActionPayload(actionPayload)) {
|
||||
throw new Error('Internal: Invalid action payload in cookie.');
|
||||
}
|
||||
return renderResult({ context, next, ...actionPayload });
|
||||
}
|
||||
|
||||
return next();
|
||||
});
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue