feat: added secure cookie env

Signed-off-by: Varun Raj <mailme@varunraj.in>
This commit is contained in:
Varun Raj
2024-09-07 19:37:18 +05:30
parent bcb12473e0
commit 23c341cba5
4 changed files with 8 additions and 3 deletions
+4 -1
View File
@@ -4,4 +4,7 @@ DB_USERNAME="" # Postgress Database Username
DB_PASSWORD="" # Postgres Database Password
DB_HOST="" # Postgres Host (IP address or hostname of the database)
DB_PORT="" # Postgres Port number (Default: 5432)
DB_DATABASE_NAME="" # Name of the database
DB_DATABASE_NAME="" # Name of the database
# Additional configuration
SECURE_COOKIE=false # Set to true to enable secure cookies
+1
View File
@@ -41,6 +41,7 @@ IMMICH_URL = "http://local-ip-of-immich:port" # Your immich instace ip address a
EXTERNAL_IMMICH_URL = "https://external-address" # External address of immich
```
Refer here for obtaining Immich API Key: https://immich.app/docs/features/command-line-interface#obtain-the-api-key
#### Method 2 - Portainer
If you're using portainer, run the docker using `docker run` and add the power tools to the same network as immich.
+1
View File
@@ -4,6 +4,7 @@ export const ENV = {
IMMICH_API_KEY: process.env.IMMICH_API_KEY as string,
DATABASE_URL: (process.env.DATABASE_URL || `postgresql://${process.env.DB_USERNAME}:${process.env.DB_PASSWORD}@${(process.env.DB_HOST || 'immich_postgres')}:${(process.env.DB_PORT || '5432')}/${process.env.DB_DATABASE_NAME}`),
JWT_SECRET: process.env.JWT_SECRET as string,
SECURE_COOKIE: process.env.SECURE_COOKIE === 'true',
};
+2 -2
View File
@@ -1,3 +1,4 @@
import { ENV } from '@/config/environment'
import type { CookieSerializeOptions } from 'cookie'
import cookie from 'cookie'
import type { IncomingMessage } from 'http'
@@ -22,8 +23,7 @@ export const serializeCookie = (
return cookie.serialize(name, String(value), {
httpOnly: true,
maxAge: 60 * 60 * 24 * 7,
sameSite: process.env.NODE_ENV === 'production' ? 'none' : 'lax',
secure: process.env.NODE_ENV === 'production',
secure: ENV.SECURE_COOKIE,
path: '/',
...options,
})