Skip to content

Commit 14c4705

Browse files
Fix inconsistent locals usage in middleware code examples (#14106)
Co-authored-by: Armand Philippot <git@armand.philippot.eu>
1 parent 4cafdc1 commit 14c4705

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/content/docs/en/guides/middleware.mdx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ Middleware also allows you to set and share request-specific information across
2323
// intercept data from a request
2424
// optionally, modify the properties in `locals`
2525
context.locals.title = "New title";
26+
context.locals.property = "information";
2627

2728
// return a Response or the result of calling `next()`
2829
return next();
@@ -62,10 +63,12 @@ You can store any type of data inside `locals`: strings, numbers, and even compl
6263
export function onRequest (context, next) {
6364
// intercept data from a request
6465
// optionally, modify the properties in `locals`
65-
context.locals.user.name = "John Wick";
66+
context.locals.user = { id: 1, name: "John Wick" };
6667
context.locals.welcomeTitle = () => {
67-
return "Welcome back " + locals.user.name;
68+
return "Welcome back " + context.locals.user.name;
6869
};
70+
context.locals.orders = new Map([["1", { product: "socks" }]]);
71+
context.locals.property = "information";
6972

7073
// return a Response or the result of calling `next()`
7174
return next();

0 commit comments

Comments
 (0)