From 3eba51aed87560d8b539e73a7b09586aeef6b01a Mon Sep 17 00:00:00 2001 From: Pooya Parsa Date: Sun, 6 Aug 2023 22:32:31 +0200 Subject: [PATCH] small updates --- .../1.guide/{4.sessions.md => 7.sessions.md} | 24 +++++++++++-------- 1 file changed, 14 insertions(+), 10 deletions(-) rename docs/content/1.guide/{4.sessions.md => 7.sessions.md} (84%) diff --git a/docs/content/1.guide/4.sessions.md b/docs/content/1.guide/7.sessions.md similarity index 84% rename from docs/content/1.guide/4.sessions.md rename to docs/content/1.guide/7.sessions.md index 5d14ddc1f4..86b011f4f7 100644 --- a/docs/content/1.guide/4.sessions.md +++ b/docs/content/1.guide/7.sessions.md @@ -5,26 +5,30 @@ icon: ri:arrow-left-right-line # Sessions -Nitro, through [unjs/h3](https://github.com/h3), supports sessions out of the box. +Nitro, supports user sessions out of the box. (through [unjs/h3](https://github.com/h3)) ::alert{type="info"} A session is a series of interactions between a client and server. Because HTTP is a stateless protocol, sessions allow association of multiple requests to the same client using a cookie which is automatically sent by the browser to the server on each request. :: -## Composables available +## Session Utilities -There is many composables you can use to manage sessions: +You can use to manage sessions with available auto imported utils: + +- `useSession(event, sessionConfig)`: Initializes a session and returns a wrapper to control it. +- `getSession(event, sessionConfig)`: Initializes or gets the current user session. +- `updateSession(event, sessionConfig)`: Updates data of the current session. +- `clearSession(event, sessionConfig)`: Clears the current session. + +Advanced utils: + +- `sealSession(event, sessionConfig)`: Encrypts the current user session. +- `unsealSession(event, sessionConfig, sealed)`: Decryptes the current user session. -- `useSession`, the most importante one since it's a wrapper around all other composables -- `getSession`, to get the current session -- `updateSession`, to update the data of the current session -- `sealSession`, to protect the current session from being modified -- `unsealSession`, to access to the current session -- `clearSession`, to clear the current session ## Use sessions -To use sessions, you've just to use the `useSession` composable and provide a string password in one of your event handler. each time a client will hit this endpoint, the composable will first try to get the session from a header named `x-h3-session` then from a cookie named `h3`. If no session is found, a new one will be created. +To use sessions, you've just to use the `useSession` composable and provide a strong password in one of your event handler. each time a client will hit this endpoint, the composable will first try to get the session from a header named `x-h3-session` then from a cookie named `h3`. If no session is found, a new one will be created. ```ts [routes/index.ts] export default defineEventHandler(async (event) => {