├── .eslintignore ├── .eslintrc.cjs ├── .github └── workflows │ └── publish.yml ├── .gitignore ├── .jshintrc ├── .npmrc ├── .prettierignore ├── .prettierrc ├── LICENSE.txt ├── README.md ├── docs ├── .gitignore ├── README.md ├── astro.config.mjs ├── package.json ├── pnpm-lock.yaml ├── public │ └── favicon.svg ├── src │ ├── assets │ │ ├── ethercorps.png │ │ ├── ethercorps_transparent.png │ │ ├── houston.webp │ │ └── logo.svg │ ├── content │ │ ├── config.ts │ │ └── docs │ │ │ ├── guides │ │ │ └── example.md │ │ │ ├── index.mdx │ │ │ └── reference │ │ │ └── example.md │ ├── env.d.ts │ └── tailwind.css ├── tailwind.config.cjs └── tsconfig.json ├── examples ├── ioredis │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── playwright.config.ts │ ├── pnpm-lock.yaml │ ├── src │ │ ├── app.css │ │ ├── app.d.ts │ │ ├── app.html │ │ ├── hooks.server.ts │ │ ├── lib │ │ │ └── session.ts │ │ └── routes │ │ │ ├── +layout.svelte │ │ │ ├── +page.server.ts │ │ │ ├── +page.svelte │ │ │ └── api │ │ │ ├── login │ │ │ └── +server.ts │ │ │ ├── logout │ │ │ └── +server.ts │ │ │ └── updateCookieData │ │ │ └── +server.ts │ ├── static │ │ ├── favicon.png │ │ └── logo.svg │ ├── svelte.config.js │ ├── tests │ │ └── test.ts │ ├── tsconfig.json │ └── vite.config.ts ├── node │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── playwright.config.ts │ ├── pnpm-lock.yaml │ ├── src │ │ ├── app.css │ │ ├── app.d.ts │ │ ├── app.html │ │ ├── hooks.server.ts │ │ ├── lib │ │ │ └── session.ts │ │ └── routes │ │ │ ├── +layout.svelte │ │ │ ├── +page.server.ts │ │ │ ├── +page.svelte │ │ │ └── api │ │ │ ├── login │ │ │ └── +server.ts │ │ │ ├── logout │ │ │ └── +server.ts │ │ │ └── updateCookieData │ │ │ └── +server.ts │ ├── static │ │ ├── favicon.png │ │ └── logo.svg │ ├── svelte.config.js │ ├── tests │ │ └── test.ts │ ├── tsconfig.json │ └── vite.config.ts └── upstash │ ├── .gitignore │ ├── README.md │ ├── package.json │ ├── playwright.config.ts │ ├── pnpm-lock.yaml │ ├── src │ ├── app.css │ ├── app.d.ts │ ├── app.html │ ├── hooks.server.ts │ ├── lib │ │ └── session.ts │ └── routes │ │ ├── +layout.svelte │ │ ├── +page.server.ts │ │ ├── +page.svelte │ │ └── api │ │ ├── login │ │ └── +server.ts │ │ ├── logout │ │ └── +server.ts │ │ └── updateCookieData │ │ └── +server.ts │ ├── static │ ├── favicon.png │ └── logo.svg │ ├── svelte.config.js │ ├── tests │ └── test.ts │ ├── tsconfig.json │ └── vite.config.ts ├── package.json ├── pnpm-lock.yaml ├── src ├── app.d.ts ├── app.html ├── index.test.ts ├── lib │ ├── index.ts │ ├── providers │ │ ├── ioredis.ts │ │ ├── redis.ts │ │ └── upstash.ts │ └── shared.ts └── routes │ ├── +page.server.ts │ └── +page.svelte ├── static ├── favicon.png └── logo.svg ├── svelte.config.js ├── tsconfig.json └── vite.config.ts /.eslintignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | 10 | # Ignore files for PNPM, NPM and YARN 11 | pnpm-lock.yaml 12 | package-lock.json 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /.eslintrc.cjs: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | root: true, 3 | extends: [ 4 | 'eslint:recommended', 5 | 'plugin:@typescript-eslint/recommended', 6 | 'plugin:svelte/recommended', 7 | 'prettier' 8 | ], 9 | parser: '@typescript-eslint/parser', 10 | plugins: ['@typescript-eslint'], 11 | parserOptions: { 12 | sourceType: 'module', 13 | ecmaVersion: 2020, 14 | extraFileExtensions: ['.svelte'] 15 | }, 16 | env: { 17 | browser: true, 18 | es2017: true, 19 | node: true 20 | }, 21 | overrides: [ 22 | { 23 | files: ['*.svelte'], 24 | parser: 'svelte-eslint-parser', 25 | parserOptions: { 26 | parser: '@typescript-eslint/parser' 27 | } 28 | } 29 | ] 30 | }; 31 | -------------------------------------------------------------------------------- /.github/workflows/publish.yml: -------------------------------------------------------------------------------- 1 | on: 2 | push: 3 | branches: master 4 | 5 | jobs: 6 | publish: 7 | runs-on: ubuntu-latest 8 | env: 9 | CI: true 10 | steps: 11 | - uses: actions/checkout@v3 12 | - uses: actions/setup-node@v3 13 | with: 14 | node-version: 20 15 | - uses: pnpm/action-setup@v2 16 | name: Install pnpm 17 | id: pnpm-install 18 | with: 19 | version: 8.6.1 20 | - run: pnpm install 21 | - run: pnpm package 22 | - uses: JS-DevTools/npm-publish@v2 23 | with: 24 | token: ${{ secrets.NPM_TOKEN }} 25 | ignore-scripts: true 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /dist 5 | /.svelte-kit 6 | /package 7 | .env 8 | .env.* 9 | !.env.example 10 | vite.config.js.timestamp-* 11 | vite.config.ts.timestamp-* 12 | .idea 13 | -------------------------------------------------------------------------------- /.jshintrc: -------------------------------------------------------------------------------- 1 | { 2 | "esversion": 6 3 | } 4 | -------------------------------------------------------------------------------- /.npmrc: -------------------------------------------------------------------------------- 1 | engine-strict=true 2 | resolution-mode=highest 3 | -------------------------------------------------------------------------------- /.prettierignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /.svelte-kit 5 | /package 6 | .env 7 | .env.* 8 | !.env.example 9 | 10 | # Ignore files for PNPM, NPM and YARN 11 | pnpm-lock.yaml 12 | package-lock.json 13 | yarn.lock 14 | -------------------------------------------------------------------------------- /.prettierrc: -------------------------------------------------------------------------------- 1 | { 2 | "useTabs": true, 3 | "singleQuote": true, 4 | "trailingComma": "none", 5 | "printWidth": 100, 6 | "plugins": ["prettier-plugin-svelte"], 7 | "pluginSearchDirs": ["."], 8 | "overrides": [{ "files": "*.svelte", "options": { "parser": "svelte" } }] 9 | } 10 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Ether Corps 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [![Contributors][contributors-shield]][contributors-url] 3 | [![Forks][forks-shield]][forks-url] 4 | [![Stargazers][stars-shield]][stars-url] 5 | [![Issues][issues-shield]][issues-url] 6 | [![MIT License][license-shield]][license-url] 7 | [![LinkedIn][linkedin-shield]][linkedin-url] 8 | 9 | 10 |
11 |
12 | 13 | Logo 14 | 15 | 16 |

SvelteKit Redis Session Manager

17 | 18 |

19 | Redis integration in SvelteKit for Session Management 20 |
21 | @ethercorps/sveltekit-redis-session 22 |
23 | Explore the docs » 24 |
25 |
26 | View Demo 27 | · 28 | Report Bug 29 | · 30 | Request Feature 31 |

32 |
33 | 34 |
35 | Table of Contents 36 |
    37 |
  1. 38 | About The Project 39 | 43 |
  2. 44 |
  3. 45 | Getting Started 46 | 50 |
  4. 51 |
  5. Usage
  6. 52 |
  7. Roadmap
  8. 53 |
  9. License
  10. 54 |
  11. Contact
  12. 55 |
  13. Acknowledgments
  14. 56 |
57 |
58 | 59 | 60 | 61 | ## About The Project 62 | 63 | [//]: # '[![Product Name Screen Shot][product-screenshot]](https://github.com/etherCorps/SK-Redis-SessionManager)' 64 | 65 | "SvelteKit-Redis-Session" stands out as an indispensable tool for developers aiming to seamlessly integrate Redis as a session manager within their SvelteKit applications. Designed with a keen attention to detail, this package ensures that managing user sessions is not only efficient but also intuitive. 66 | 67 |

(back to top)

68 | 69 | ## Key Features 70 | 71 | - `Simplicity at its Core`: With intuitive functions, developers can effortlessly store and retrieve data without wading through complexities. 72 | - `Enhanced Security`: Understanding the need for robust data protection, the package offers signature & encryption for session data. 73 | - `Intelligent Session Management`: The package intelligently handles session expiration, reducing the manual oversight typically needed. 74 | - `Bespoke Customization`: Recognizing that one size doesn't fit all, "SvelteKit-Redis-Session" offers high customizability, allowing developers to tailor its functionalities to their distinct needs, and in turn, enhancing application performance. 75 | - `For all runtimes`: As of now we have so many runtimes cloudflare workers, vercel, netlify. 76 | - `Support for multiple redis libraries`: We support `redis` & `ioredis` out of the box. 77 | - `Support for @upstash/redis`: It's mandatory if you are working with workers, edge and serverless. Cloudflare workers doesn't support TCP. 78 | 79 | ### Built With 80 | 81 | - [![SvelteKit][SvelteKit]][SvelteKit-url] 82 | - [![Redis][Redis]][Redis-url] 83 | - [![Svelte][Svelte.dev]][Svelte-url] 84 | 85 |

(back to top)

86 | 87 | 88 | 89 | ## Getting Started 90 | 91 | This is an example of how you may give instructions on setting up your project locally. 92 | To get a local copy up and running follow these simple example steps. 93 | 94 | ### Prerequisites 95 | 96 | This is an example of how to list things you need to use the software and how to install them. 97 | 98 | - Install the `@ethercorps/sveltekit-redis-session` 99 | ```sh 100 | pnpm i @ethercorps/sveltekit-redis-session 101 | ``` 102 | - Choose which redis library you are using: 103 | - `redis`: Official redis nodeJs implementation 104 | ```sh 105 | pnpm i redis 106 | ``` 107 | - `ioredis`: A robust, performance-focused and full-featured Redis client for Node.js. 108 | ```sh 109 | pnpm i ioredis 110 | ``` 111 | - `@upstash/redis`: is an HTTP/REST based Redis client built on top of Upstash REST API. 112 | ```sh 113 | pnpm i @upstash/redis 114 | ``` 115 | 116 | ### Setup 117 | 118 | [//]: # 'Guide to how' 119 | [//]: # 'to use @ethercorps/SvelteKit-redis-session' 120 | 121 | 1. First, we need to make instance of it to use everywhere in the project. 122 | ```ts 123 | import { IoRedisSessionStore } from '@ethercorps/SvelteKit-redis-session'; 124 | import Redis from 'ioredis'; 125 | export const sessionManager = new IoRedisSessionStore({ 126 | redisClient: new Redis(), // Required A pre-initiated redis client 127 | secret: 'your-secret-key', // Required A secret key for encryption and other things, 128 | cookieName: 'session', // CookieName to be saved in cookies for browser Default session 129 | prefix: 'sk-session', // Prefix for Redis Keys Default sk-session 130 | signed: true, // Do you want to sign your cookies Default true 131 | encrypted: false, // Do you want to encrypt your cookies using 'aes-256-cbc' algorithm Default false 132 | useTTL: true, // Do you wanna use redis's Expire key functionality Default false 133 | renewSessionBeforeExpire: false, // Do you wanna update session expire time in built function Default false 134 | renewBeforeSeconds: 30 * 60, // If renewSessionBeforeExpire is true define your renew before time in seconds Default 30 minutes 135 | serializer: JSON, // You can define your own serializer functions to stringify and parse sessionData for redis Default JSON 136 | cookiesOptions: { 137 | path: '/', 138 | httpOnly: true, 139 | sameSite: 'strict', 140 | secure: !dev, // From SvelteKit "$app/environment" 141 | maxAge: 60 * 60 * 24 // You have to define time in seconds and it's also used for redis key expiry time 142 | } // You have more options these are default used in package for more check sveltekit CookieSerializeOptions type. 143 | }); 144 | ``` 145 | > These are the default config example you can use as per your need and make it better for your use. 146 | > I have written an article to explain more about this package link for article. 147 | 2. To create a new session and add cookies for user after authentication 148 | 149 | ```ts 150 | // Example it's a +page.server.ts 151 | import sessionManager from 'sessionManagerFile'; 152 | 153 | export const actions: Actions = { 154 | login: async ({ req, cookies, locals }) => { 155 | const formdata = await request.formData(); 156 | // Form validation && user validation 157 | const { data, error, message } = sessionManager.createSession(cookies, userData, userId); 158 | // data is the value we added to cookies, check for error which is a boolean and message. 159 | /* add data to locals too for accessing data from client */ 160 | throw redirect(307, '/dashboard'); 161 | } 162 | }; 163 | ``` 164 | 165 | 3. To get session data for the cookie 166 | 167 | ```ts 168 | /* hooks.server.ts */ 169 | import sessionManager from 'sessionManagerFile'; 170 | 171 | export const handle: Handle = async ({ event, resolve }) => { 172 | /* your validation logic */ 173 | const { data, error, message } = sessionManager.getSession(event.cookies); 174 | // data is the User session data we saved to redis while login, check for error which is a boolean and message. 175 | /* do error check and then set data to locals as per your logic */ 176 | }; 177 | ``` 178 | 179 | 4. To update session expiry in redis and cookies 180 | 181 | ```ts 182 | // in any server side file or endpoint where you can access browser cookies 183 | import sessionManager from 'sessionManagerFile'; 184 | const { data, error, message } = await sessionManager.updateSessionExpiry(cookies); 185 | // data is going to be null or key which is updated, error is a boolean value and message a string 186 | ``` 187 | 188 | 5. To update session data in redis and cookies 189 | 190 | ```ts 191 | // in any server side file or endpoint where you can access browser cookies 192 | import sessionManager from 'sessionManagerFile'; 193 | const { data, error, message } = await sessionManager.updateSession(cookies, newSessionData); 194 | // data is going to be null or key which is updated, error is a boolean value and message a string 195 | ``` 196 | 197 | 6. To delete session from redis and cookie from browser 198 | 199 | ```ts 200 | // Example it's a +page.server.ts 201 | 202 | import sessionManager from 'sessionManagerFile'; 203 | export const actions: Actions = { 204 | logout: async ({ cookies, locals }) => { 205 | const { data, error, message } = await sessionManager.deleteSession(cookies); 206 | // data is the value we deleted key, check for error which is a boolean and message. 207 | /* clear your locals too */ 208 | throw redirect(307, '/login'); 209 | } 210 | }; 211 | ``` 212 | 213 | 7. To get all sessions of a user from redis and cookie from browser 214 | 215 | ```ts 216 | // Example it's a +server.ts 217 | 218 | import sessionManager from 'sessionManagerFile'; 219 | 220 | export const GET: RequestHandler = async ({ cookies, locals }) => { 221 | const { data, error, message } = await sessionManager.getSessionsByUserId(userId); 222 | // data is the session data array, check for error which is a boolean and message. 223 | /* clear your locals too */ 224 | return json({data}) 225 | } 226 | }; 227 | ``` 228 | 229 |

(back to top)

230 | 231 | 232 | 233 | ## Usage 234 | 235 | Examples are going to be added soon. 236 | 237 | _For more examples, please refer to the [Examples](https://github.com/etherCorps/SK-Redis-SessionManager/tree/master/examples)_ 238 | 239 |

(back to top)

240 | 241 | 242 | 243 | ## Roadmap 244 | 245 | See the [open issues](https://github.com/etherCorps/SK-Redis-SessionManager/issues) for a full list of proposed 246 | features (and known issues). 247 | 248 |

(back to top)

249 | 250 | 251 | 252 | [//]: # '## Contributing' 253 | [//]: # 254 | [//]: # 'Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any' 255 | [//]: # 'contributions you make are **greatly appreciated**.' 256 | [//]: # 257 | [//]: # 'If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also' 258 | [//]: # 'simply open an issue with the tag "enhancement".' 259 | [//]: # "Don't forget to give the project a star! Thanks again!" 260 | [//]: # 261 | [//]: # '1. Fork the Project' 262 | [//]: # '2. Create your Feature Branch (`git checkout -b feature/AmazingFeature`)' 263 | [//]: # "3. Commit your Changes (`git commit -m 'Add some AmazingFeature'`)" 264 | [//]: # '4. Push to the Branch (`git push origin feature/AmazingFeature`)' 265 | [//]: # '5. Open a Pull Request' 266 | [//]: # 267 | [//]: # '

(back to top)

' 268 | 269 | 270 | 271 | ## License 272 | 273 | Distributed under the MIT License. See `LICENSE.txt` for more information. 274 | 275 |

(back to top)

276 | 277 | 278 | 279 | ## Contact 280 | 281 | Your Name - [@theether0](https://twitter.com/theether0) - meenashivam9650@gmail.com 282 | 283 | Project 284 | Link: [https://github.com/etherCorps/SK-Redis-SessionManager](https://github.com/etherCorps/SK-Redis-SessionManager) 285 | 286 |

(back to top)

287 | 288 | 289 | 290 | ## Acknowledgments 291 | 292 | - [logos-by-larkef from landingfolio](https://www.landingfolio.com/logos-by-larkef) :: For logo 293 | - [connect-redis by TJ Holowaychuk](https://github.com/tj/connect-redis/tree/master) :: Creator of connect redis for express session. 294 | - []() 295 | 296 |

(back to top)

297 | 298 | 299 | 300 | 301 | [contributors-shield]: https://img.shields.io/github/contributors/etherCorps/SK-Redis-SessionManager.svg?style=for-the-badge 302 | [contributors-url]: https://github.com/etherCorps/SK-Redis-SessionManager/graphs/contributors 303 | [forks-shield]: https://img.shields.io/github/forks/etherCorps/SK-Redis-SessionManager.svg?style=for-the-badge 304 | [forks-url]: https://github.com/etherCorps/SK-Redis-SessionManager/network/members 305 | [stars-shield]: https://img.shields.io/github/stars/etherCorps/SK-Redis-SessionManager.svg?style=for-the-badge 306 | [stars-url]: https://github.com/etherCorps/SK-Redis-SessionManager/stargazers 307 | [issues-shield]: https://img.shields.io/github/issues/etherCorps/SK-Redis-SessionManager.svg?style=for-the-badge 308 | [issues-url]: https://github.com/etherCorps/SK-Redis-SessionManager/issues 309 | [license-shield]: https://img.shields.io/github/license/etherCorps/SK-Redis-SessionManager.svg?style=for-the-badge 310 | [license-url]: https://github.com/etherCorps/SK-Redis-SessionManager/blob/master/LICENSE.txt 311 | [linkedin-shield]: https://img.shields.io/badge/-LinkedIn-black.svg?style=for-the-badge&logo=linkedin&colorB=555 312 | [linkedin-url]: https://linkedin.com/in/theether0 313 | [product-screenshot]: static/screenshot.png 314 | [SvelteKit]: https://img.shields.io/badge/sveltekit-000000?style=for-the-badge&logo=svelte&logoColor=white 315 | [SvelteKit-url]: https://kit.svelte.dev 316 | [Redis]: https://img.shields.io/badge/Redis-DD0031?style=for-the-badge&logo=Redis&logoColor=white 317 | [Redis-url]: https://redis.io/ 318 | [Svelte.dev]: https://img.shields.io/badge/Svelte-4A4A55?style=for-the-badge&logo=svelte&logoColor=FF3E00 319 | [Svelte-url]: https://svelte.dev/ 320 | -------------------------------------------------------------------------------- /docs/.gitignore: -------------------------------------------------------------------------------- 1 | # build output 2 | dist/ 3 | # generated types 4 | .astro/ 5 | 6 | # dependencies 7 | node_modules/ 8 | 9 | # logs 10 | npm-debug.log* 11 | yarn-debug.log* 12 | yarn-error.log* 13 | pnpm-debug.log* 14 | 15 | 16 | # environment variables 17 | .env 18 | .env.production 19 | 20 | # macOS-specific files 21 | .DS_Store 22 | .vscode 23 | -------------------------------------------------------------------------------- /docs/README.md: -------------------------------------------------------------------------------- 1 | # Starlight Starter Kit: Tailwind 2 | 3 | ``` 4 | npm create astro@latest -- --template starlight/tailwind 5 | ``` 6 | 7 | [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/withastro/starlight/tree/main/examples/tailwind) 8 | [![Open with CodeSandbox](https://assets.codesandbox.io/github/button-edit-lime.svg)](https://codesandbox.io/p/sandbox/github/withastro/starlight/tree/main/examples/tailwind) 9 | 10 | > 🧑‍🚀 **Seasoned astronaut?** Delete this file. Have fun! 11 | 12 | ## 🚀 Project Structure 13 | 14 | Inside of your Astro + Starlight project, you'll see the following folders and files: 15 | 16 | ``` 17 | . 18 | ├── public/ 19 | ├── src/ 20 | │ ├── assets/ 21 | │ ├── content/ 22 | │ │ ├── docs/ 23 | │ │ └── config.ts 24 | │ └── env.d.ts 25 | ├── astro.config.mjs 26 | ├── package.json 27 | ├── tailwind.config.cjs 28 | └── tsconfig.json 29 | ``` 30 | 31 | Starlight looks for `.md` or `.mdx` files in the `src/content/docs/` directory. Each file is exposed as a route based on its file name. 32 | 33 | Images can be added to `src/assets/` and embedded in Markdown with a relative link. 34 | 35 | Static assets, like favicons, can be placed in the `public/` directory. 36 | 37 | ## 🧞 Commands 38 | 39 | All commands are run from the root of the project, from a terminal: 40 | 41 | | Command | Action | 42 | | :------------------------ | :----------------------------------------------- | 43 | | `npm install` | Installs dependencies | 44 | | `npm run dev` | Starts local dev server at `localhost:3000` | 45 | | `npm run build` | Build your production site to `./dist/` | 46 | | `npm run preview` | Preview your build locally, before deploying | 47 | | `npm run astro ...` | Run CLI commands like `astro add`, `astro check` | 48 | | `npm run astro -- --help` | Get help using the Astro CLI | 49 | 50 | ## 👀 Want to learn more? 51 | 52 | Check out [Starlight’s docs](https://starlight.astro.build/), read [the Astro documentation](https://docs.astro.build), or jump into the [Astro Discord server](https://astro.build/chat). 53 | -------------------------------------------------------------------------------- /docs/astro.config.mjs: -------------------------------------------------------------------------------- 1 | import { defineConfig } from 'astro/config'; 2 | import starlight from '@astrojs/starlight'; 3 | import tailwind from '@astrojs/tailwind'; 4 | 5 | // https://astro.build/config 6 | export default defineConfig({ 7 | integrations: [ 8 | starlight({ 9 | title: 'SK Redis Session', 10 | logo: { 11 | src: './src/assets/logo.svg' 12 | }, 13 | social: { 14 | github: 'https://github.com/etherCorps/SK-Redis-SessionManager', 15 | discord: 'https://discord.gg/y8yN33wQ' 16 | }, 17 | sidebar: [ 18 | { 19 | label: 'Guides', 20 | items: [ 21 | // Each item here is one entry in the navigation menu. 22 | { label: 'Example Guide', link: '/guides/example/' } 23 | ] 24 | }, 25 | { 26 | label: 'Reference', 27 | autogenerate: { directory: 'reference' } 28 | } 29 | ], 30 | customCss: ['./src/tailwind.css'] 31 | }), 32 | tailwind({ applyBaseStyles: false }) 33 | ], 34 | // Process images with sharp: https://docs.astro.build/en/guides/assets/#using-sharp 35 | image: { 36 | service: { 37 | entrypoint: 'astro/assets/services/sharp' 38 | } 39 | } 40 | }); 41 | -------------------------------------------------------------------------------- /docs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "", 3 | "type": "module", 4 | "version": "0.0.1", 5 | "scripts": { 6 | "dev": "astro dev", 7 | "start": "astro dev", 8 | "build": "astro build", 9 | "preview": "astro preview", 10 | "astro": "astro" 11 | }, 12 | "dependencies": { 13 | "@astrojs/starlight": "^0.8.0", 14 | "@astrojs/starlight-tailwind": "^1.0.2", 15 | "@astrojs/tailwind": "^4.0.0", 16 | "astro": "^2.10.3", 17 | "sharp": "^0.32.3", 18 | "tailwindcss": "^3.3.3" 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /docs/public/favicon.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /docs/src/assets/ethercorps.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/etherCorps/SK-Redis-SessionManager/d134b04321cc0039940058b1baaf4ae1d2681dbb/docs/src/assets/ethercorps.png -------------------------------------------------------------------------------- /docs/src/assets/ethercorps_transparent.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/etherCorps/SK-Redis-SessionManager/d134b04321cc0039940058b1baaf4ae1d2681dbb/docs/src/assets/ethercorps_transparent.png -------------------------------------------------------------------------------- /docs/src/assets/houston.webp: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/etherCorps/SK-Redis-SessionManager/d134b04321cc0039940058b1baaf4ae1d2681dbb/docs/src/assets/houston.webp -------------------------------------------------------------------------------- /docs/src/assets/logo.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | -------------------------------------------------------------------------------- /docs/src/content/config.ts: -------------------------------------------------------------------------------- 1 | import { defineCollection } from 'astro:content'; 2 | import { docsSchema, i18nSchema } from '@astrojs/starlight/schema'; 3 | 4 | export const collections = { 5 | docs: defineCollection({ schema: docsSchema() }), 6 | i18n: defineCollection({ type: 'data', schema: i18nSchema() }) 7 | }; 8 | -------------------------------------------------------------------------------- /docs/src/content/docs/guides/example.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Example Guide 3 | description: A guide in my new Starlight docs site. 4 | --- 5 | 6 | Guides lead a user through a specific task they want to accomplish, often with a sequence of steps. 7 | Writing a good guide requires thinking about what your users are trying to do. 8 | 9 | ## Further reading 10 | 11 | - Read [about how-to guides](https://diataxis.fr/how-to-guides/) in the Diátaxis framework 12 | -------------------------------------------------------------------------------- /docs/src/content/docs/index.mdx: -------------------------------------------------------------------------------- 1 | --- 2 | title: Welcome to Sveltekit Redis Session Manager 3 | description: Manage your session in Sveltekit with redis for all runtimes. 4 | template: splash 5 | hero: 6 | title: | 7 | Welcome to Redis Session Manger with 8 | 14 | Sveltekit 15 | 16 | tagline: Sveltekit redis session manager for all runtimes. 17 | image: 18 | alt: 'Sveltekit Redis Session Manger' 19 | html: '' 20 | actions: 21 | - text: Documentation 22 | link: /guides/example/ 23 | icon: right-arrow 24 | variant: primary 25 | - text: Read the Starlight docs 26 | link: https://starlight.astro.build 27 | icon: external 28 | --- 29 | 30 | import { Card, CardGrid } from '@astrojs/starlight/components'; 31 | 32 | ## Next steps 33 | 34 | 35 | 36 | Edit `src/content/docs/index.mdx` to see this page change. 37 | 38 | 39 | Add Markdown or MDX files to `src/content/docs` to create new pages. 40 | 41 | 42 | Edit your `sidebar` and other config in `astro.config.mjs`. 43 | 44 | 45 | Learn more in [the Starlight Docs](https://starlight.astro.build/). 46 | 47 | 48 | -------------------------------------------------------------------------------- /docs/src/content/docs/reference/example.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Example Reference 3 | description: A reference page in my new Starlight docs site. 4 | --- 5 | 6 | Reference pages are ideal for outlining how things work in terse and clear terms. 7 | Less concerned with telling a story or addressing a specific use case, they should give a comprehensive outline of what your documenting. 8 | 9 | ## Further reading 10 | 11 | - Read [about reference](https://diataxis.fr/reference/) in the Diátaxis framework 12 | -------------------------------------------------------------------------------- /docs/src/env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | /// 3 | -------------------------------------------------------------------------------- /docs/src/tailwind.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | 5 | /* 6 | Add additional Tailwind styles to this file, for example with @layer: 7 | https://tailwindcss.com/docs/adding-custom-styles#using-css-and-layer 8 | */ 9 | -------------------------------------------------------------------------------- /docs/tailwind.config.cjs: -------------------------------------------------------------------------------- 1 | const colors = require('tailwindcss/colors'); 2 | const starlightPlugin = require('@astrojs/starlight-tailwind'); 3 | 4 | /** @type {import('tailwindcss').Config} */ 5 | module.exports = { 6 | content: ['./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}'], 7 | theme: { 8 | extend: { 9 | colors: { 10 | // Your preferred accent color. Indigo is closest to Starlight’s defaults. 11 | accent: colors.amber, 12 | // Your preferred gray scale. Zinc is closest to Starlight’s defaults. 13 | gray: colors.slate 14 | } 15 | } 16 | }, 17 | plugins: [starlightPlugin()] 18 | }; 19 | -------------------------------------------------------------------------------- /docs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "astro/tsconfigs/base" 3 | } 4 | -------------------------------------------------------------------------------- /examples/ioredis/.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | node_modules 3 | /build 4 | /dist 5 | /.svelte-kit 6 | /package 7 | .env 8 | .env.* 9 | !.env.example 10 | vite.config.js.timestamp-* 11 | vite.config.ts.timestamp-* 12 | .idea 13 | -------------------------------------------------------------------------------- /examples/ioredis/README.md: -------------------------------------------------------------------------------- 1 | # create-svelte 2 | 3 | Everything you need to build a Svelte project, powered by [`create-svelte`](https://github.com/sveltejs/kit/tree/master/packages/create-svelte). 4 | 5 | ## Creating a project 6 | 7 | If you're seeing this, you've probably already done this step. Congrats! 8 | 9 | ```bash 10 | # create a new project in the current directory 11 | npm create svelte@latest 12 | 13 | # create a new project in my-app 14 | npm create svelte@latest my-app 15 | ``` 16 | 17 | ## Developing 18 | 19 | Once you've created a project and installed dependencies with `npm install` (or `pnpm install` or `yarn`), start a development server: 20 | 21 | ```bash 22 | npm run dev 23 | 24 | # or start the server and open the app in a new browser tab 25 | npm run dev -- --open 26 | ``` 27 | 28 | ## Building 29 | 30 | To create a production version of your app: 31 | 32 | ```bash 33 | npm run build 34 | ``` 35 | 36 | You can preview the production build with `npm run preview`. 37 | 38 | > To deploy your app, you may need to install an [adapter](https://kit.svelte.dev/docs/adapters) for your target environment. 39 | -------------------------------------------------------------------------------- /examples/ioredis/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ioredis-vercel", 3 | "version": "0.0.1", 4 | "private": true, 5 | "scripts": { 6 | "dev": "vite dev --host", 7 | "build": "vite build", 8 | "build:pac": "cd ../.. && pnpm install && pnpm build && cd examples/ioredis && pnpm build", 9 | "preview": "vite preview", 10 | "test": "playwright test", 11 | "check": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json", 12 | "check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch", 13 | "lint": "prettier --plugin-search-dir . --check . && eslint .", 14 | "format": "prettier --plugin-search-dir . --write ." 15 | }, 16 | "devDependencies": { 17 | "@playwright/test": "^1.37.1", 18 | "@sveltejs/adapter-vercel": "^2.4.3", 19 | "@sveltejs/kit": "^1.23.0", 20 | "@typescript-eslint/eslint-plugin": "^5.62.0", 21 | "@typescript-eslint/parser": "^5.62.0", 22 | "eslint": "^8.48.0", 23 | "eslint-config-prettier": "^8.10.0", 24 | "eslint-plugin-svelte3": "^4.0.0", 25 | "ioredis": "^5.3.2", 26 | "prettier": "^2.8.8", 27 | "prettier-plugin-svelte": "^2.10.1", 28 | "svelte": "^4.0.0", 29 | "svelte-check": "^3.5.0", 30 | "svelte-french-toast": "^1.2.0", 31 | "tslib": "^2.6.2", 32 | "typescript": "^5.0.0", 33 | "vite": "^4.4.9" 34 | }, 35 | "type": "module", 36 | "dependencies": { 37 | "@ethercorps/sveltekit-redis-session": "link:../../" 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /examples/ioredis/playwright.config.ts: -------------------------------------------------------------------------------- 1 | import type { PlaywrightTestConfig } from '@playwright/test'; 2 | 3 | const config: PlaywrightTestConfig = { 4 | webServer: { 5 | command: 'npm run build && npm run preview', 6 | port: 4173 7 | }, 8 | testDir: 'tests' 9 | }; 10 | 11 | export default config; 12 | -------------------------------------------------------------------------------- /examples/ioredis/src/app.css: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/etherCorps/SK-Redis-SessionManager/d134b04321cc0039940058b1baaf4ae1d2681dbb/examples/ioredis/src/app.css -------------------------------------------------------------------------------- /examples/ioredis/src/app.d.ts: -------------------------------------------------------------------------------- 1 | // See https://kit.svelte.dev/docs/types#app 2 | // for information about these interfaces 3 | // and what to do when importing types 4 | declare global { 5 | namespace App { 6 | // interface Error {} 7 | interface Locals { 8 | isUserLoggedIn: boolean; 9 | user: { 10 | email: string; 11 | name: string; 12 | } | null; 13 | } 14 | // interface PageData {} 15 | // interface Platform {} 16 | } 17 | } 18 | 19 | export {}; 20 | -------------------------------------------------------------------------------- /examples/ioredis/src/app.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | %sveltekit.head% 8 | 9 | 10 |
%sveltekit.body%
11 | 12 | 13 | -------------------------------------------------------------------------------- /examples/ioredis/src/hooks.server.ts: -------------------------------------------------------------------------------- 1 | import type { Handle } from '@sveltejs/kit'; 2 | import { sessionManager } from '$lib/session'; 3 | import { redirect } from '@sveltejs/kit'; 4 | 5 | export const handle: Handle = async ({ event, resolve }) => { 6 | const userSession = await sessionManager.getSession(await event.cookies); 7 | 8 | event.locals = { 9 | isUserLoggedIn: false, 10 | user: null 11 | }; 12 | if (userSession.error) { 13 | await sessionManager.deleteCookie(await event.cookies); 14 | return resolve(event); 15 | } 16 | if (userSession && userSession.data) { 17 | event.locals = { 18 | isUserLoggedIn: true, 19 | user: userSession?.data 20 | }; 21 | } 22 | return resolve(event); 23 | }; 24 | -------------------------------------------------------------------------------- /examples/ioredis/src/lib/session.ts: -------------------------------------------------------------------------------- 1 | import { 2 | IoRedisSessionStore, 3 | type ioRedisSessionOptions 4 | } from '@ethercorps/sveltekit-redis-session'; 5 | import { SECRET, REDIS_URL } from '$env/static/private'; 6 | import Redis from 'ioredis'; 7 | 8 | const sessionOptions: ioRedisSessionOptions = { 9 | redisClient: new Redis(REDIS_URL), 10 | secret: SECRET, 11 | sessionPrefix: 'vercel-ioredis-srs-example-session', 12 | userSessionsPrefix: 'vercel-ioredis-srs-example-user', 13 | cookieName: 'session', 14 | cookiesOptions: { 15 | maxAge: 10 * 60 16 | } 17 | }; 18 | export const sessionManager = new IoRedisSessionStore(sessionOptions); 19 | -------------------------------------------------------------------------------- /examples/ioredis/src/routes/+layout.svelte: -------------------------------------------------------------------------------- 1 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 |
13 | -------------------------------------------------------------------------------- /examples/ioredis/src/routes/+page.server.ts: -------------------------------------------------------------------------------- 1 | import type { Actions } from '@sveltejs/kit'; 2 | import { fail } from '@sveltejs/kit'; 3 | import { sessionManager } from '$lib/session'; 4 | import type { PageServerLoad } from './$types'; 5 | 6 | export let ssr = true; 7 | export const load: PageServerLoad = async ({ locals }) => { 8 | return { 9 | user: locals.user, 10 | isAuthenticated: locals.isUserLoggedIn 11 | }; 12 | }; 13 | 14 | export const actions: Actions = { 15 | default: async ({ request, cookies }) => { 16 | const formData = await request.formData(); 17 | if ( 18 | formData.get('email') !== 'shivam@example.com' || 19 | formData.get('password') !== 'Shivam@Meena' 20 | ) { 21 | return fail(400, { 22 | data: Object.fromEntries(formData), 23 | message: 'Check form for errors' 24 | }); 25 | } 26 | 27 | const { data, error, message } = await sessionManager.createSession( 28 | cookies, 29 | { email: formData.get('email') }, 30 | '1' 31 | ); 32 | if (error) { 33 | console.log(message); 34 | return fail(400, { 35 | data: Object.fromEntries(formData), 36 | message 37 | }); 38 | } 39 | console.log(data); 40 | return { success: true, message }; 41 | } 42 | }; 43 | -------------------------------------------------------------------------------- /examples/ioredis/src/routes/+page.svelte: -------------------------------------------------------------------------------- 1 | 52 | 53 |