Skip to content

Commit

Permalink
fix(forms): session name
Browse files Browse the repository at this point in the history
  • Loading branch information
ido-pluto committed Nov 18, 2023
1 parent 4a32211 commit 3c96ea5
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
15 changes: 9 additions & 6 deletions packages/forms/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
<div align="center">

# Astro Forms

<img src ="https://raw.githubusercontent.com/withastro-utils/forms/main/assets/logo.webp" width="100px"/><br/>
<img src="../../assets/logo.rounded.png" alt="Astro Utils" height="300px"/>
</div>


Reactive forms for Astro without any JavaScript!
> Reactive forms for Astro without any JavaScript!
### Why use this?
- Allow client side & server side validation & parsing (number, boolean...)
Expand Down Expand Up @@ -134,16 +137,16 @@ You can also use this as a simple on click hook
```astro
---
import { Button } from "@astro-utils/forms/forms.js";
const { asSession } = Astro.locals
const { session } = Astro.locals
function increaseCounter() {
asSession.counter ??= 0
asSession.counter++
session.counter ??= 0
session.counter++
}
---
<Layout>
<Button onClick={increaseCounter}>++</Button>
{asSession.counter}
{session.counter}
<Layout/>
```

Expand Down
2 changes: 1 addition & 1 deletion packages/forms/src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function astroForms(settings: Partial<FormsSettings> = {}){

return async function onRequest ({ locals, request, cookies }: APIContext , next: MiddlewareNextResponse) {
const session = new JWTSession(cookies);
locals.amSession = session.sessionData;
locals.session = session.sessionData;

await validateFrom({cookies, locals, request}, FORM_OPTIONS.csrf);
const response = await next();
Expand Down

0 comments on commit 3c96ea5

Please sign in to comment.