Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ JWT_ACCESS_KEY=change-me-access-token-secret
ACCESS_TOKEN_EXPIRED_IN=1h
JWT_REFRESH_KEY=change-me-refresh-token-secret
REFRESH_TOKEN_EXPIRED_IN=7d
FRONTEND_URL=
FRONTEND_URL=http://localhost:5173
COOKIE_SECURE=false
COOKIE_SAME_SITE=lax

# Elasticsearch
ELASTICSEARCH_URL=http://elasticsearch:9200
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ services:
JWT_REFRESH_KEY: ${JWT_REFRESH_KEY:-change-me-refresh-token-secret}
ACCESS_TOKEN_EXPIRED_IN: ${ACCESS_TOKEN_EXPIRED_IN:-1h}
REFRESH_TOKEN_EXPIRED_IN: ${REFRESH_TOKEN_EXPIRED_IN:-7d}
FRONTEND_URL: ${FRONTEND_URL:-}
FRONTEND_URL: ${FRONTEND_URL:-http://localhost:5173}
COOKIE_SECURE: ${COOKIE_SECURE:-false}
COOKIE_SAME_SITE: ${COOKIE_SAME_SITE:-lax}
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_USERNAME: ${ELASTICSEARCH_USERNAME:-elastic}
ELASTICSEARCH_PASSWORD: ${ELASTICSEARCH_PASSWORD:-change_me}
Expand Down
5 changes: 5 additions & 0 deletions src/config/env.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@
.asString() as ms.StringValue,

FRONTEND_URL: env.get('FRONTEND_URL').asString(),
COOKIE_SECURE: env.get('COOKIE_SECURE').default('false').asBoolStrict(),
COOKIE_SAME_SITE: env

Check failure on line 27 in src/config/env.ts

View workflow job for this annotation

GitHub Actions / lint

Replace `⏎····.get('COOKIE_SAME_SITE')⏎····.default('lax')⏎····.asEnum(['strict',·'lax',·'none'])·as·'strict'·|·'lax'` with `.get('COOKIE_SAME_SITE').default('lax').asEnum(['strict',·'lax',·'none'])·as⏎····|·'strict'⏎····|·'lax'⏎···`
.get('COOKIE_SAME_SITE')
.default('lax')
.asEnum(['strict', 'lax', 'none']) as 'strict' | 'lax' | 'none',

ELASTICSEARCH_URL: env.get('ELASTICSEARCH_URL').default('http://localhost:9200').asUrlString(),
ELASTICSEARCH_USERNAME: env.get('ELASTICSEARCH_USERNAME').default('elastic').asString(),
Expand Down
8 changes: 4 additions & 4 deletions src/modules/Auth/services/Auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export const getLoginContext = (req: Request): LoginContext => ({
export const setRefreshTokenCookie = (res: Response, refreshToken: string): void => {
res.cookie('refreshToken', refreshToken, {
httpOnly: true,
secure: config.NODE_ENV === 'production',
sameSite: 'strict',
secure: config.COOKIE_SECURE,
sameSite: config.COOKIE_SAME_SITE,
maxAge: ms(config.REFRESH_TOKEN_EXPIRED_IN),
path: '/api/v1/auth',
});
Expand All @@ -35,8 +35,8 @@ export const setRefreshTokenCookie = (res: Response, refreshToken: string): void
export const clearRefreshTokenCookie = (res: Response): void => {
res.clearCookie('refreshToken', {
httpOnly: true,
secure: config.NODE_ENV === 'production',
sameSite: 'strict',
secure: config.COOKIE_SECURE,
sameSite: config.COOKIE_SAME_SITE,
path: '/api/v1/auth',
});
};
Expand Down
Loading