Skip to content

Commit f69de6a

Browse files
authored
fix form actions docs (#11470)
Co-authored-by: Rich Harris <rich.harris@vercel.com>
1 parent 0d6e5e3 commit f69de6a

File tree

1 file changed

+4
-10
lines changed

1 file changed

+4
-10
lines changed

documentation/docs/20-core-concepts/30-form-actions.md

+4-10
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ Each action receives a `RequestEvent` object, allowing you to read the data with
108108
```js
109109
// @errors: 2304
110110
/// file: src/routes/#/+page.server.js
111-
import { base } from '$app/paths';
112-
113111
/** @type {import('./$types').PageServerLoad} */
114112
export async function load({ cookies }) {
115113
const user = await db.getUserFromSession(cookies.get('sessionid'));
@@ -124,7 +122,7 @@ export const actions = {
124122
const password = data.get('password');
125123

126124
const user = await db.getUser(email);
127-
cookies.set('sessionid', await db.createSession(user), { path: base});
125+
cookies.set('sessionid', await db.createSession(user), { path: '/' });
128126

129127
return { success: true };
130128
},
@@ -158,7 +156,6 @@ If the request couldn't be processed because of invalid data, you can return val
158156
```diff
159157
/// file: src/routes/#/+page.server.js
160158
+import { fail } from '@sveltejs/kit';
161-
import { base } from '$app/paths';
162159

163160
/** @type {import('./$types').Actions} */
164161
export const actions = {
@@ -177,7 +174,7 @@ export const actions = {
177174
+ return fail(400, { email, incorrect: true });
178175
+ }
179176

180-
cookies.set('sessionid', await db.createSession(user), { path: base });
177+
cookies.set('sessionid', await db.createSession(user), { path: '/' });
181178

182179
return { success: true };
183180
},
@@ -217,7 +214,6 @@ Redirects (and errors) work exactly the same as in [`load`](load#redirects):
217214
```diff
218215
/// file: src/routes/#/+page.server.js
219216
+import { fail, redirect } from '@sveltejs/kit';
220-
import { base } from '$app/paths';
221217

222218
/** @type {import('./$types').Actions} */
223219
export const actions = {
@@ -235,7 +231,7 @@ export const actions = {
235231
return fail(400, { email, incorrect: true });
236232
}
237233

238-
cookies.set('sessionid', await db.createSession(user), { path: base });
234+
cookies.set('sessionid', await db.createSession(user), { path: '/' });
239235

240236
+ if (url.searchParams.has('redirectTo')) {
241237
+ redirect(303, url.searchParams.get('redirectTo'));
@@ -297,8 +293,6 @@ declare namespace App {
297293

298294
// @filename: index.js
299295
// ---cut---
300-
import { base } from '$app/paths';
301-
302296
/** @type {import('./$types').PageServerLoad} */
303297
export function load(event) {
304298
return {
@@ -309,7 +303,7 @@ export function load(event) {
309303
/** @type {import('./$types').Actions} */
310304
export const actions = {
311305
logout: async (event) => {
312-
event.cookies.delete('sessionid', { path: base });
306+
event.cookies.delete('sessionid', { path: '/' });
313307
event.locals.user = null;
314308
}
315309
};

0 commit comments

Comments
 (0)