tethys.backend/config/session.ts

128 lines
3.6 KiB
TypeScript
Raw Permalink Normal View History

2023-03-03 15:54:28 +00:00
/**
* Config source: https://git.io/JeYHp
*
* Feel free to let us know via PR, if you find something broken in this config
* file.
*/
2024-03-14 19:25:27 +00:00
import env from '#start/env';
import app from '@adonisjs/core/services/app';
import { defineConfig, stores } from '@adonisjs/session';
2023-03-03 15:54:28 +00:00
const sessionConfig = defineConfig({
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Enable/Disable sessions
|--------------------------------------------------------------------------
|
| Setting the following property to "false" will disable the session for the
| entire application
|
*/
2023-03-03 15:54:28 +00:00
enabled: true,
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Driver
|--------------------------------------------------------------------------
|
| The session driver to use. You can choose between one of the following
| drivers.
|
| - cookie (Uses signed cookies to store session values)
| - file (Uses filesystem to store session values)
| - redis (Uses redis. Make sure to install "@adonisjs/redis" as well)
|
| Note: Switching drivers will make existing sessions invalid.
|
*/
// driver: env.get('SESSION_DRIVER'),
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Cookie name
|--------------------------------------------------------------------------
|
| The name of the cookie that will hold the session id.
|
*/
2023-03-03 15:54:28 +00:00
cookieName: 'adonis-session',
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Clear session when browser closes
|--------------------------------------------------------------------------
|
| Whether or not you want to destroy the session when browser closes. Setting
| this value to `true` will ignore the `age`.
|
*/
2023-03-03 15:54:28 +00:00
clearWithBrowser: false,
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Session age
|--------------------------------------------------------------------------
|
| The duration for which session stays active after no activity. A new HTTP
| request to the server is considered as activity.
|
| The value can be a number in milliseconds or a string that must be valid
| as per https://npmjs.org/package/ms package.
|
| Example: `2 days`, `2.5 hrs`, `1y`, `5s` and so on.
|
*/
2023-03-03 15:54:28 +00:00
age: '2h',
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Cookie values
|--------------------------------------------------------------------------
|
| The cookie settings are used to setup the session id cookie and also the
| driver will use the same values.
|
*/
2023-03-03 15:54:28 +00:00
cookie: {
path: '/',
httpOnly: true,
secure: false, //app.inProduction,
2023-03-03 15:54:28 +00:00
sameSite: false,
},
2024-03-14 19:25:27 +00:00
/**
* The store to use. Make sure to validate the environment
* variable in order to infer the store name without any
* errors.
*/
store: env.get('SESSION_DRIVER'),
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Configuration for the file driver
|--------------------------------------------------------------------------
|
| The file driver needs absolute path to the directory in which sessions
| must be stored.
|
*/
// file: {
// location: app.tmpPath('sessions'),
// },
2023-03-03 15:54:28 +00:00
/*
2024-03-14 19:25:27 +00:00
|--------------------------------------------------------------------------
| Redis driver
|--------------------------------------------------------------------------
|
| The redis connection you want session driver to use. The same connection
| must be defined inside `config/redis.ts` file as well.
|
*/
// redisConnection: 'local',
2024-03-14 19:25:27 +00:00
stores: {
cookie: stores.cookie(),
},
2023-03-03 15:54:28 +00:00
});
export default sessionConfig;