[{"data":1,"prerenderedAt":1275},["ShallowReactive",2],{"navigation":3,"-examples-handle-session":189,"-examples-handle-session-surround":1270},[4,91,138,166,173],{"title":5,"path":6,"stem":7,"children":8,"icon":90},"Guide","/guide","1.guide/0.index",[9,12,53,69],{"title":10,"path":6,"stem":7,"icon":11},"Getting Started","pixel:play",{"title":5,"icon":13,"path":14,"stem":15,"children":16,"page":52},"ph:book-open-duotone","/guide/basics","1.guide/1.basics",[17,22,27,32,37,42,47],{"title":18,"path":19,"stem":20,"icon":21},"Request Lifecycle","/guide/basics/lifecycle","1.guide/1.basics/1.lifecycle","icon-park-outline:handle-round",{"title":23,"path":24,"stem":25,"icon":26},"Routing","/guide/basics/routing","1.guide/1.basics/2.routing","solar:routing-bold",{"title":28,"path":29,"stem":30,"icon":31},"Middleware","/guide/basics/middleware","1.guide/1.basics/3.middleware","mdi:middleware-outline",{"title":33,"path":34,"stem":35,"icon":36},"Event Handlers","/guide/basics/handler","1.guide/1.basics/4.handler","mdi:function",{"title":38,"path":39,"stem":40,"icon":41},"Sending Response","/guide/basics/response","1.guide/1.basics/5.response","tabler:json",{"title":43,"path":44,"stem":45,"icon":46},"Error Handling","/guide/basics/error","1.guide/1.basics/6.error","tabler:error-404",{"title":48,"path":49,"stem":50,"icon":51},"Nested Apps","/guide/basics/nested-apps","1.guide/1.basics/7.nested-apps","material-symbols-light:layers-outline",false,{"title":54,"icon":55,"path":56,"stem":57,"children":58,"page":52},"API","material-symbols-light:api-rounded","/guide/api","1.guide/900.api",[59,64],{"title":60,"path":61,"stem":62,"icon":63},"H3","/guide/api/h3","1.guide/900.api/1.h3","material-symbols:bolt-rounded",{"title":65,"path":66,"stem":67,"icon":68},"H3Event","/guide/api/h3event","1.guide/900.api/2.h3event","material-symbols:data-object-rounded",{"title":70,"icon":71,"path":72,"stem":73,"children":74,"page":52},"Advanced","hugeicons:more-01","/guide/advanced","1.guide/901.advanced",[75,80,85],{"title":76,"path":77,"stem":78,"icon":79},"Plugins","/guide/advanced/plugins","1.guide/901.advanced/1.plugins","clarity:plugin-line",{"title":81,"path":82,"stem":83,"icon":84},"WebSockets","/guide/advanced/websocket","1.guide/901.advanced/2.websocket","hugeicons:live-streaming-02",{"title":86,"path":87,"stem":88,"icon":89},"Nightly Builds","/guide/advanced/nightly","1.guide/901.advanced/9.nightly","game-icons:barn-owl","i-ph:book-open-duotone",{"title":92,"path":93,"stem":94,"children":95,"icon":97},"Utils","/utils","2.utils/0.index",[96,98,103,108,113,118,123,128,133],{"title":92,"path":93,"stem":94,"icon":97},"ph:function-bold",{"title":99,"path":100,"stem":101,"icon":102},"Request","/utils/request","2.utils/1.request","material-symbols-light:input",{"title":104,"path":105,"stem":106,"icon":107},"Response","/utils/response","2.utils/2.response","material-symbols-light:output",{"title":109,"path":110,"stem":111,"icon":112},"Cookie","/utils/cookie","2.utils/3.cookie","material-symbols:cookie-outline",{"title":114,"path":115,"stem":116,"icon":117},"Security","/utils/security","2.utils/4.security","wpf:key-security",{"title":119,"path":120,"stem":121,"icon":122},"Proxy","/utils/proxy","2.utils/5.proxy","arcticons:super-proxy",{"title":124,"path":125,"stem":126,"icon":127},"MCP","/utils/mcp","2.utils/6.mcp","material-symbols:swap-calls",{"title":129,"path":130,"stem":131,"icon":132},"More utils","/utils/more","2.utils/9.more","mingcute:plus-line",{"title":134,"path":135,"stem":136,"icon":137},"Community","/utils/community","2.utils/99.community","lets-icons:external",{"title":139,"path":140,"stem":141,"children":142,"icon":144},"Examples","/examples","4.examples/0.index",[143,145,150,154,158,162],{"title":139,"path":140,"stem":141,"icon":144},"ph:code",{"title":146,"path":147,"stem":148,"icon":149},"Cookies","/examples/handle-cookie","4.examples/handle-cookie","ph:arrow-right",{"title":151,"path":152,"stem":153,"icon":149},"Sessions","/examples/handle-session","4.examples/handle-session",{"title":155,"path":156,"stem":157,"icon":149},"Static Assets","/examples/serve-static-assets","4.examples/serve-static-assets",{"title":159,"path":160,"stem":161,"icon":149},"Stream Response","/examples/stream-response","4.examples/stream-response",{"title":163,"path":164,"stem":165,"icon":149},"Validate Data","/examples/validate-data","4.examples/validate-data",{"title":167,"path":168,"stem":169,"children":170,"icon":172},"Migration","/migration","5.migration/0.index",[171],{"title":167,"path":168,"stem":169,"icon":172},"icons8:up-round",{"title":174,"path":175,"stem":176,"children":177},"Blog","/blog","99.blog",[178,181,185],{"title":174,"path":175,"stem":179,"icon":180},"99.blog/index","i-lucide-file-text",{"title":182,"path":183,"stem":184,"icon":180},"H3 1.8 - Towards the Edge of the Web","/blog/v1.8","99.blog/1.v1.8",{"title":186,"path":187,"stem":188,"icon":180},"H3 v2 beta","/blog/v2-beta","99.blog/2.v2-beta",{"id":190,"title":151,"body":191,"description":1264,"extension":1265,"meta":1266,"navigation":1267,"path":152,"seo":1268,"stem":153,"__hash__":1269},"content/4.examples/handle-session.md",{"type":192,"value":193,"toc":1256,"icon":149},"minimark",[194,198,201,230,236,241,253,382,392,403,413,419,423,432,515,522,526,534,701,704,710,713,722,726,734,840,848,852,858,1019,1060,1073,1077,1083,1244,1252],[195,196,197],"p",{},"A session is a way to remember users using cookies. It is a very common method for authenticating users or saving data about them, such as their language or preferences on the web.",[195,199,200],{},"H3 provides many utilities to handle sessions:",[202,203,204,212,218,224],"ul",{},[205,206,207,211],"li",{},[208,209,210],"code",{},"useSession"," initializes a session and returns a wrapper to control it.",[205,213,214,217],{},[208,215,216],{},"getSession"," initializes or retrieves the current user session.",[205,219,220,223],{},[208,221,222],{},"updateSession"," updates the data of the current session.",[205,225,226,229],{},[208,227,228],{},"clearSession"," clears the current session.",[195,231,232,233,235],{},"Most of the time, you will use ",[208,234,210],{}," to manipulate the session.",[237,238,240],"h2",{"id":239},"initialize-a-session","Initialize a Session",[195,242,243,244,246,247,252],{},"To initialize a session, you need to use ",[208,245,210],{}," in an ",[248,249,251],"a",{"href":250},"/guide/handler","event handler",":",[254,255,260],"pre",{"className":256,"code":257,"language":258,"meta":259,"style":259},"language-js shiki shiki-themes github-light github-dark github-dark","import { useSession } from \"h3\";\n\napp.use(async (event) => {\n  const session = await useSession(event, {\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  // do something...\n});\n","js","",[208,261,262,285,292,324,346,358,364,369,376],{"__ignoreMap":259},[263,264,267,271,275,278,282],"span",{"class":265,"line":266},"line",1,[263,268,270],{"class":269},"so5gQ","import",[263,272,274],{"class":273},"slsVL"," { useSession } ",[263,276,277],{"class":269},"from",[263,279,281],{"class":280},"sfrk1"," \"h3\"",[263,283,284],{"class":273},";\n",[263,286,288],{"class":265,"line":287},2,[263,289,291],{"emptyLinePlaceholder":290},true,"\n",[263,293,295,298,302,305,308,311,315,318,321],{"class":265,"line":294},3,[263,296,297],{"class":273},"app.",[263,299,301],{"class":300},"shcOC","use",[263,303,304],{"class":273},"(",[263,306,307],{"class":269},"async",[263,309,310],{"class":273}," (",[263,312,314],{"class":313},"sQHwn","event",[263,316,317],{"class":273},") ",[263,319,320],{"class":269},"=>",[263,322,323],{"class":273}," {\n",[263,325,327,330,334,337,340,343],{"class":265,"line":326},4,[263,328,329],{"class":269},"  const",[263,331,333],{"class":332},"suiK_"," session",[263,335,336],{"class":269}," =",[263,338,339],{"class":269}," await",[263,341,342],{"class":300}," useSession",[263,344,345],{"class":273},"(event, {\n",[263,347,349,352,355],{"class":265,"line":348},5,[263,350,351],{"class":273},"    password: ",[263,353,354],{"class":280},"\"80d42cfb-1cd2-462c-8f17-e3237d9027e9\"",[263,356,357],{"class":273},",\n",[263,359,361],{"class":265,"line":360},6,[263,362,363],{"class":273},"  });\n",[263,365,367],{"class":265,"line":366},7,[263,368,291],{"emptyLinePlaceholder":290},[263,370,372],{"class":265,"line":371},8,[263,373,375],{"class":374},"sCsY4","  // do something...\n",[263,377,379],{"class":265,"line":378},9,[263,380,381],{"class":273},"});\n",[383,384,385],"warning",{},[195,386,387,388,391],{},"\nYou must provide a password to encrypt the session. The examples below use a hardcoded value so they stay readable, but in a real app load it from an environment variable such as ",[208,389,390],{},"process.env.SESSION_PASSWORD",", keep it a strong secret of at least 32 characters, and never commit it to source control.",[195,393,394,395,398,399,402],{},"This will initialize a session and return an header ",[208,396,397],{},"Set-Cookie"," with a cookie named ",[208,400,401],{},"h3"," and an encrypted content.",[195,404,405,406,408,409,412],{},"If the request contains a cookie named ",[208,407,401],{}," or a header named ",[208,410,411],{},"x-h3-session",", the session will be initialized with the content of the cookie or the header.",[414,415,416],"note",{},[195,417,418],{},"\nThe header take precedence over the cookie.",[237,420,422],{"id":421},"get-data-from-a-session","Get Data from a Session",[195,424,425,426,428,429,431],{},"To get data from a session, we will still use ",[208,427,210],{},". Under the hood, it will use ",[208,430,216],{}," to get the session.",[254,433,435],{"className":256,"code":434,"language":258,"meta":259,"style":259},"import { useSession } from \"h3\";\n\napp.use(async (event) => {\n  const session = await useSession(event, {\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  return session.data;\n});\n",[208,436,437,449,453,473,487,495,499,503,511],{"__ignoreMap":259},[263,438,439,441,443,445,447],{"class":265,"line":266},[263,440,270],{"class":269},[263,442,274],{"class":273},[263,444,277],{"class":269},[263,446,281],{"class":280},[263,448,284],{"class":273},[263,450,451],{"class":265,"line":287},[263,452,291],{"emptyLinePlaceholder":290},[263,454,455,457,459,461,463,465,467,469,471],{"class":265,"line":294},[263,456,297],{"class":273},[263,458,301],{"class":300},[263,460,304],{"class":273},[263,462,307],{"class":269},[263,464,310],{"class":273},[263,466,314],{"class":313},[263,468,317],{"class":273},[263,470,320],{"class":269},[263,472,323],{"class":273},[263,474,475,477,479,481,483,485],{"class":265,"line":326},[263,476,329],{"class":269},[263,478,333],{"class":332},[263,480,336],{"class":269},[263,482,339],{"class":269},[263,484,342],{"class":300},[263,486,345],{"class":273},[263,488,489,491,493],{"class":265,"line":348},[263,490,351],{"class":273},[263,492,354],{"class":280},[263,494,357],{"class":273},[263,496,497],{"class":265,"line":360},[263,498,363],{"class":273},[263,500,501],{"class":265,"line":366},[263,502,291],{"emptyLinePlaceholder":290},[263,504,505,508],{"class":265,"line":371},[263,506,507],{"class":269},"  return",[263,509,510],{"class":273}," session.data;\n",[263,512,513],{"class":265,"line":378},[263,514,381],{"class":273},[195,516,517,518,521],{},"Data are stored in the ",[208,519,520],{},"data"," property of the session. If there is no data, it will be an empty object.",[237,523,525],{"id":524},"add-data-to-a-session","Add Data to a Session",[195,527,528,529,428,531,533],{},"To add data to a session, we will still use ",[208,530,210],{},[208,532,222],{}," to update the session.",[254,535,537],{"className":256,"code":536,"language":258,"meta":259,"style":259},"import { useSession } from \"h3\";\n\napp.use(async (event) => {\n  const session = await useSession(event, {\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  const count = (session.data.count || 0) + 1;\n  await session.update({\n    count: count,\n  });\n\n  return count === 0 ? \"Hello world!\" : `Hello world! You have visited this page ${count} times.`;\n});\n",[208,538,539,551,555,575,589,597,601,605,633,647,653,658,663,696],{"__ignoreMap":259},[263,540,541,543,545,547,549],{"class":265,"line":266},[263,542,270],{"class":269},[263,544,274],{"class":273},[263,546,277],{"class":269},[263,548,281],{"class":280},[263,550,284],{"class":273},[263,552,553],{"class":265,"line":287},[263,554,291],{"emptyLinePlaceholder":290},[263,556,557,559,561,563,565,567,569,571,573],{"class":265,"line":294},[263,558,297],{"class":273},[263,560,301],{"class":300},[263,562,304],{"class":273},[263,564,307],{"class":269},[263,566,310],{"class":273},[263,568,314],{"class":313},[263,570,317],{"class":273},[263,572,320],{"class":269},[263,574,323],{"class":273},[263,576,577,579,581,583,585,587],{"class":265,"line":326},[263,578,329],{"class":269},[263,580,333],{"class":332},[263,582,336],{"class":269},[263,584,339],{"class":269},[263,586,342],{"class":300},[263,588,345],{"class":273},[263,590,591,593,595],{"class":265,"line":348},[263,592,351],{"class":273},[263,594,354],{"class":280},[263,596,357],{"class":273},[263,598,599],{"class":265,"line":360},[263,600,363],{"class":273},[263,602,603],{"class":265,"line":366},[263,604,291],{"emptyLinePlaceholder":290},[263,606,607,609,612,614,617,620,623,625,628,631],{"class":265,"line":371},[263,608,329],{"class":269},[263,610,611],{"class":332}," count",[263,613,336],{"class":269},[263,615,616],{"class":273}," (session.data.count ",[263,618,619],{"class":269},"||",[263,621,622],{"class":332}," 0",[263,624,317],{"class":273},[263,626,627],{"class":269},"+",[263,629,630],{"class":332}," 1",[263,632,284],{"class":273},[263,634,635,638,641,644],{"class":265,"line":378},[263,636,637],{"class":269},"  await",[263,639,640],{"class":273}," session.",[263,642,643],{"class":300},"update",[263,645,646],{"class":273},"({\n",[263,648,650],{"class":265,"line":649},10,[263,651,652],{"class":273},"    count: count,\n",[263,654,656],{"class":265,"line":655},11,[263,657,363],{"class":273},[263,659,661],{"class":265,"line":660},12,[263,662,291],{"emptyLinePlaceholder":290},[263,664,666,668,671,674,676,679,682,685,688,691,694],{"class":265,"line":665},13,[263,667,507],{"class":269},[263,669,670],{"class":273}," count ",[263,672,673],{"class":269},"===",[263,675,622],{"class":332},[263,677,678],{"class":269}," ?",[263,680,681],{"class":280}," \"Hello world!\"",[263,683,684],{"class":269}," :",[263,686,687],{"class":280}," `Hello world! You have visited this page ${",[263,689,690],{"class":273},"count",[263,692,693],{"class":280},"} times.`",[263,695,284],{"class":273},[263,697,699],{"class":265,"line":698},14,[263,700,381],{"class":273},[195,702,703],{},"What is happening here?",[195,705,706,707,709],{},"We try to get a session from the request. If there is no session, a new one will be created. Then, we increment the ",[208,708,690],{}," property of the session and we update the session with the new value. Finally, we return a message with the number of times the user visited the page.",[195,711,712],{},"Try to visit the page multiple times and you will see the number of times you visited the page.",[414,714,715],{},[195,716,717,718,721],{},"\nIf you use a CLI tool like ",[208,719,720],{},"curl"," to test this example, you will not see the number of times you visited the page because the CLI tool does not save cookies. You must get the cookie from the response and send it back to the server.",[237,723,725],{"id":724},"clear-a-session","Clear a Session",[195,727,728,729,428,731,733],{},"To clear a session, we will still use ",[208,730,210],{},[208,732,228],{}," to clear the session.",[254,735,737],{"className":256,"code":736,"language":258,"meta":259,"style":259},"import { useSession } from \"h3\";\n\napp.use(\"/clear\", async (event) => {\n  const session = await useSession(event, {\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  await session.clear();\n\n  return \"Session cleared\";\n});\n",[208,738,739,751,755,781,795,803,807,811,823,827,836],{"__ignoreMap":259},[263,740,741,743,745,747,749],{"class":265,"line":266},[263,742,270],{"class":269},[263,744,274],{"class":273},[263,746,277],{"class":269},[263,748,281],{"class":280},[263,750,284],{"class":273},[263,752,753],{"class":265,"line":287},[263,754,291],{"emptyLinePlaceholder":290},[263,756,757,759,761,763,766,769,771,773,775,777,779],{"class":265,"line":294},[263,758,297],{"class":273},[263,760,301],{"class":300},[263,762,304],{"class":273},[263,764,765],{"class":280},"\"/clear\"",[263,767,768],{"class":273},", ",[263,770,307],{"class":269},[263,772,310],{"class":273},[263,774,314],{"class":313},[263,776,317],{"class":273},[263,778,320],{"class":269},[263,780,323],{"class":273},[263,782,783,785,787,789,791,793],{"class":265,"line":326},[263,784,329],{"class":269},[263,786,333],{"class":332},[263,788,336],{"class":269},[263,790,339],{"class":269},[263,792,342],{"class":300},[263,794,345],{"class":273},[263,796,797,799,801],{"class":265,"line":348},[263,798,351],{"class":273},[263,800,354],{"class":280},[263,802,357],{"class":273},[263,804,805],{"class":265,"line":360},[263,806,363],{"class":273},[263,808,809],{"class":265,"line":366},[263,810,291],{"emptyLinePlaceholder":290},[263,812,813,815,817,820],{"class":265,"line":371},[263,814,637],{"class":269},[263,816,640],{"class":273},[263,818,819],{"class":300},"clear",[263,821,822],{"class":273},"();\n",[263,824,825],{"class":265,"line":378},[263,826,291],{"emptyLinePlaceholder":290},[263,828,829,831,834],{"class":265,"line":649},[263,830,507],{"class":269},[263,832,833],{"class":280}," \"Session cleared\"",[263,835,284],{"class":273},[263,837,838],{"class":265,"line":655},[263,839,381],{"class":273},[195,841,842,843,845,846,733],{},"H3 will send a header ",[208,844,397],{}," with an empty cookie named ",[208,847,401],{},[237,849,851],{"id":850},"options","Options",[195,853,854,855,857],{},"When to use ",[208,856,210],{},", you can pass an object with options as the second argument to configure the session:",[254,859,861],{"className":256,"code":860,"language":258,"meta":259,"style":259},"import { useSession } from \"h3\";\n\napp.use(async (event) => {\n  const session = await useSession(event, {\n    name: \"my-session\",\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n    cookie: {\n      httpOnly: true,\n      secure: true,\n      sameSite: \"strict\",\n    },\n    maxAge: 60 * 60 * 24 * 7, // 7 days\n  });\n\n  return session.data;\n});\n",[208,862,863,875,879,899,913,923,931,936,946,955,965,970,999,1003,1007,1014],{"__ignoreMap":259},[263,864,865,867,869,871,873],{"class":265,"line":266},[263,866,270],{"class":269},[263,868,274],{"class":273},[263,870,277],{"class":269},[263,872,281],{"class":280},[263,874,284],{"class":273},[263,876,877],{"class":265,"line":287},[263,878,291],{"emptyLinePlaceholder":290},[263,880,881,883,885,887,889,891,893,895,897],{"class":265,"line":294},[263,882,297],{"class":273},[263,884,301],{"class":300},[263,886,304],{"class":273},[263,888,307],{"class":269},[263,890,310],{"class":273},[263,892,314],{"class":313},[263,894,317],{"class":273},[263,896,320],{"class":269},[263,898,323],{"class":273},[263,900,901,903,905,907,909,911],{"class":265,"line":326},[263,902,329],{"class":269},[263,904,333],{"class":332},[263,906,336],{"class":269},[263,908,339],{"class":269},[263,910,342],{"class":300},[263,912,345],{"class":273},[263,914,915,918,921],{"class":265,"line":348},[263,916,917],{"class":273},"    name: ",[263,919,920],{"class":280},"\"my-session\"",[263,922,357],{"class":273},[263,924,925,927,929],{"class":265,"line":360},[263,926,351],{"class":273},[263,928,354],{"class":280},[263,930,357],{"class":273},[263,932,933],{"class":265,"line":366},[263,934,935],{"class":273},"    cookie: {\n",[263,937,938,941,944],{"class":265,"line":371},[263,939,940],{"class":273},"      httpOnly: ",[263,942,943],{"class":332},"true",[263,945,357],{"class":273},[263,947,948,951,953],{"class":265,"line":378},[263,949,950],{"class":273},"      secure: ",[263,952,943],{"class":332},[263,954,357],{"class":273},[263,956,957,960,963],{"class":265,"line":649},[263,958,959],{"class":273},"      sameSite: ",[263,961,962],{"class":280},"\"strict\"",[263,964,357],{"class":273},[263,966,967],{"class":265,"line":655},[263,968,969],{"class":273},"    },\n",[263,971,972,975,978,981,984,986,989,991,994,996],{"class":265,"line":660},[263,973,974],{"class":273},"    maxAge: ",[263,976,977],{"class":332},"60",[263,979,980],{"class":269}," *",[263,982,983],{"class":332}," 60",[263,985,980],{"class":269},[263,987,988],{"class":332}," 24",[263,990,980],{"class":269},[263,992,993],{"class":332}," 7",[263,995,768],{"class":273},[263,997,998],{"class":374},"// 7 days\n",[263,1000,1001],{"class":265,"line":665},[263,1002,363],{"class":273},[263,1004,1005],{"class":265,"line":698},[263,1006,291],{"emptyLinePlaceholder":290},[263,1008,1010,1012],{"class":265,"line":1009},15,[263,1011,507],{"class":269},[263,1013,510],{"class":273},[263,1015,1017],{"class":265,"line":1016},16,[263,1018,381],{"class":273},[195,1020,1021,1022,1025,1026,1029,1030,1032,1033,1035,1036,1039,1040,1042,1043,1045,1046,1048,1049,1052,1053,1056,1057,1059],{},"Every option is optional except ",[208,1023,1024],{},"password",". The ",[208,1027,1028],{},"name"," option is worth calling out: it sets the cookie used to store the session and defaults to ",[208,1031,401],{},". H3 also reads the session from a request header derived from ",[208,1034,1028],{},", which it normalizes to lowercase as ",[208,1037,1038],{},"x-${name.toLowerCase()}-session",", so the default name ",[208,1041,401],{}," produces the ",[208,1044,411],{}," header seen earlier. A mixed-case ",[208,1047,1028],{}," like ",[208,1050,1051],{},"MyApp"," still resolves to a lowercase ",[208,1054,1055],{},"x-myapp-session"," header, while the cookie keeps the original casing. That default is why the earlier examples set a cookie named ",[208,1058,401],{},".",[414,1061,1062],{},[195,1063,1064,1065,1068,1069,1072],{},"\nThe ",[208,1066,1067],{},"secure: true"," option tells the browser to only store and send the cookie over HTTPS. When developing locally over plain HTTP, compliant browsers (notably Safari and iOS, and Chrome on some local domains) silently drop the cookie, so the session will not persist. Set ",[208,1070,1071],{},"cookie: { secure: false }"," during local development to work around this.",[237,1074,1076],{"id":1075},"use-multiple-sessions","Use Multiple Sessions",[195,1078,1079,1080,1082],{},"Because each session is stored under its own ",[208,1081,1028],{},", you can run several independent sessions on the same request. They live in separate cookies and never overwrite each other, which is useful for keeping unrelated concerns apart, such as a long-lived auth session and a short-lived flash message:",[254,1084,1086],{"className":256,"code":1085,"language":258,"meta":259,"style":259},"import { useSession } from \"h3\";\n\napp.use(async (event) => {\n  const auth = await useSession(event, {\n    name: \"auth\",\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  const flash = await useSession(event, {\n    name: \"flash\",\n    password: \"80d42cfb-1cd2-462c-8f17-e3237d9027e9\",\n  });\n\n  await flash.update({ message: \"Saved!\" });\n\n  // `auth` and `flash` are backed by different cookies, so they stay separate\n  return { user: auth.data.user, flash: flash.data.message };\n});\n",[208,1087,1088,1100,1104,1124,1139,1148,1156,1160,1164,1179,1188,1196,1200,1204,1222,1226,1231,1239],{"__ignoreMap":259},[263,1089,1090,1092,1094,1096,1098],{"class":265,"line":266},[263,1091,270],{"class":269},[263,1093,274],{"class":273},[263,1095,277],{"class":269},[263,1097,281],{"class":280},[263,1099,284],{"class":273},[263,1101,1102],{"class":265,"line":287},[263,1103,291],{"emptyLinePlaceholder":290},[263,1105,1106,1108,1110,1112,1114,1116,1118,1120,1122],{"class":265,"line":294},[263,1107,297],{"class":273},[263,1109,301],{"class":300},[263,1111,304],{"class":273},[263,1113,307],{"class":269},[263,1115,310],{"class":273},[263,1117,314],{"class":313},[263,1119,317],{"class":273},[263,1121,320],{"class":269},[263,1123,323],{"class":273},[263,1125,1126,1128,1131,1133,1135,1137],{"class":265,"line":326},[263,1127,329],{"class":269},[263,1129,1130],{"class":332}," auth",[263,1132,336],{"class":269},[263,1134,339],{"class":269},[263,1136,342],{"class":300},[263,1138,345],{"class":273},[263,1140,1141,1143,1146],{"class":265,"line":348},[263,1142,917],{"class":273},[263,1144,1145],{"class":280},"\"auth\"",[263,1147,357],{"class":273},[263,1149,1150,1152,1154],{"class":265,"line":360},[263,1151,351],{"class":273},[263,1153,354],{"class":280},[263,1155,357],{"class":273},[263,1157,1158],{"class":265,"line":366},[263,1159,363],{"class":273},[263,1161,1162],{"class":265,"line":371},[263,1163,291],{"emptyLinePlaceholder":290},[263,1165,1166,1168,1171,1173,1175,1177],{"class":265,"line":378},[263,1167,329],{"class":269},[263,1169,1170],{"class":332}," flash",[263,1172,336],{"class":269},[263,1174,339],{"class":269},[263,1176,342],{"class":300},[263,1178,345],{"class":273},[263,1180,1181,1183,1186],{"class":265,"line":649},[263,1182,917],{"class":273},[263,1184,1185],{"class":280},"\"flash\"",[263,1187,357],{"class":273},[263,1189,1190,1192,1194],{"class":265,"line":655},[263,1191,351],{"class":273},[263,1193,354],{"class":280},[263,1195,357],{"class":273},[263,1197,1198],{"class":265,"line":660},[263,1199,363],{"class":273},[263,1201,1202],{"class":265,"line":665},[263,1203,291],{"emptyLinePlaceholder":290},[263,1205,1206,1208,1211,1213,1216,1219],{"class":265,"line":698},[263,1207,637],{"class":269},[263,1209,1210],{"class":273}," flash.",[263,1212,643],{"class":300},[263,1214,1215],{"class":273},"({ message: ",[263,1217,1218],{"class":280},"\"Saved!\"",[263,1220,1221],{"class":273}," });\n",[263,1223,1224],{"class":265,"line":1009},[263,1225,291],{"emptyLinePlaceholder":290},[263,1227,1228],{"class":265,"line":1016},[263,1229,1230],{"class":374},"  // `auth` and `flash` are backed by different cookies, so they stay separate\n",[263,1232,1234,1236],{"class":265,"line":1233},17,[263,1235,507],{"class":269},[263,1237,1238],{"class":273}," { user: auth.data.user, flash: flash.data.message };\n",[263,1240,1242],{"class":265,"line":1241},18,[263,1243,381],{"class":273},[414,1245,1246],{},[195,1247,1248,1249,1251],{},"\nGive each session a distinct ",[208,1250,1028],{},". Two sessions that share a name share the same cookie, so the last write wins.",[1253,1254,1255],"style",{},"html pre.shiki code .so5gQ, html code.shiki .so5gQ{--shiki-light:#D73A49;--shiki-default:#F97583;--shiki-dark:#F97583}html pre.shiki code .slsVL, html code.shiki .slsVL{--shiki-light:#24292E;--shiki-default:#E1E4E8;--shiki-dark:#E1E4E8}html pre.shiki code .sfrk1, html code.shiki .sfrk1{--shiki-light:#032F62;--shiki-default:#9ECBFF;--shiki-dark:#9ECBFF}html pre.shiki code .shcOC, html code.shiki .shcOC{--shiki-light:#6F42C1;--shiki-default:#B392F0;--shiki-dark:#B392F0}html pre.shiki code .sQHwn, html code.shiki .sQHwn{--shiki-light:#E36209;--shiki-default:#FFAB70;--shiki-dark:#FFAB70}html pre.shiki code .suiK_, html code.shiki .suiK_{--shiki-light:#005CC5;--shiki-default:#79B8FF;--shiki-dark:#79B8FF}html pre.shiki code .sCsY4, html code.shiki .sCsY4{--shiki-light:#6A737D;--shiki-default:#6A737D;--shiki-dark:#6A737D}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":259,"searchDepth":287,"depth":287,"links":1257},[1258,1259,1260,1261,1262,1263],{"id":239,"depth":287,"text":240},{"id":421,"depth":287,"text":422},{"id":524,"depth":287,"text":525},{"id":724,"depth":287,"text":725},{"id":850,"depth":287,"text":851},{"id":1075,"depth":287,"text":1076},"Remember your users using a session.","md",{"icon":149},{"icon":149},{"title":151,"description":1264},"INsxA8y8IjHCnkHwAQ2s9QAaf-aJXEdNB-ETlRMTvzE",[1271,1273],{"title":146,"path":147,"stem":148,"description":1272,"icon":149,"children":-1},"Use cookies to store data on the client.",{"title":155,"path":156,"stem":157,"description":1274,"icon":149,"children":-1},"Serve static assets such as HTML, images, CSS, JavaScript, etc.",1783115412036]