Skip to content

Commit

Permalink
chore: update dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Sep 18, 2024
1 parent 41beb6a commit 561202d
Show file tree
Hide file tree
Showing 4 changed files with 289 additions and 281 deletions.
9 changes: 9 additions & 0 deletions app/utils/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/

import 'dotenv/config'
import type { CookieOptions } from '@remix-run/node'
import * as v from 'valibot'
import { logger } from './common'

Expand Down Expand Up @@ -41,6 +42,14 @@ const EnvSchema = v.object({
SMTP_EMAIL_FROM: v.optional(v.string(), 'Remix Mailer <[email protected]>'),
})

export const GlobalCookiesOptions: Omit<CookieOptions, 'name' | 'expires'> = {
path: '/',
sameSite: 'lax',
httpOnly: true,
secure: process.env.NODE_ENV !== 'development',
secrets: [process.env.APP_SECRET_KEY],
}

export type LogLevel = v.InferInput<typeof LogLevelSchema>

declare global {
Expand Down
29 changes: 6 additions & 23 deletions app/utils/theme.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,18 @@
* Credits to Matt Stobbs: https://github.com/mattstobbs/remix-dark-mode
*/

import { type CookieOptions, createCookieSessionStorage } from '@remix-run/node'
import { createCookieSessionStorage } from '@remix-run/node'
import { Theme, isTheme } from '#/context/providers/theme-provider'
import { GlobalCookiesOptions } from '#/utils/env.server'

/**
* Determines if the application is running in development mode.
*/
const isDevelopment = process.env.NODE_ENV === 'development'
const expirationTime = new Date(Date.now() + 30 * 24 * 60 * 60 * 1000) // 30 days from now

/**
* Configuration options for the theme cookie.
*/
const cookiesOptions: Omit<CookieOptions, 'name' | 'expires'> = {
path: '/',
sameSite: 'lax',
secure: !isDevelopment,
secrets: !isDevelopment ? [process.env.APP_SECRET_KEY] : undefined,
httpOnly: true,
}
// Expired in 720 hours / 30 days from now
const cookiesExpiry = new Date(Date.now() + 3600 * 1000 * 720)

/**
* Creates a session storage for managing theme preferences.
*/
const themeStorage = createCookieSessionStorage({
cookie: {
name: 'remix_start_theme',
expires: expirationTime,
...cookiesOptions,
},
cookie: { name: 'remix_start_theme', ...GlobalCookiesOptions },
})

/**
Expand All @@ -47,7 +30,7 @@ async function getThemeSession(request: Request) {
return isTheme(themeValue) ? themeValue : Theme.DARK
},
setTheme: (theme: Theme) => session.set('theme', theme),
commit: () => themeStorage.commitSession(session, cookiesOptions),
commit: () => themeStorage.commitSession(session, { expires: cookiesExpiry }),
}
}

Expand Down
26 changes: 13 additions & 13 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,14 @@
"@playwright/test": "^1.47.1",
"@remix-run/dev": "^2.12.0",
"@remix-run/testing": "^2.12.0",
"@storybook/addon-essentials": "^8.3.0",
"@storybook/addon-interactions": "^8.3.0",
"@storybook/addon-links": "^8.3.0",
"@storybook/blocks": "^8.3.0",
"@storybook/react-vite": "^8.3.0",
"@storybook/react": "^8.3.0",
"@storybook/test": "^8.3.0",
"@storybook/theming": "^8.3.0",
"@storybook/addon-essentials": "^8.3.1",
"@storybook/addon-interactions": "^8.3.1",
"@storybook/addon-links": "^8.3.1",
"@storybook/blocks": "^8.3.1",
"@storybook/react-vite": "^8.3.1",
"@storybook/react": "^8.3.1",
"@storybook/test": "^8.3.1",
"@storybook/theming": "^8.3.1",
"@swc-node/register": "^1.10.9",
"@swc/cli": "0.4.1-nightly.20240914",
"@swc/core": "^1.7.26",
Expand All @@ -106,25 +106,25 @@
"@types/morgan": "^1.9.9",
"@types/node": "^22.5.5",
"@types/react-dom": "^18.3.0",
"@types/react": "^18.3.6",
"@types/react": "^18.3.7",
"@vitest/coverage-istanbul": "^2.1.1",
"@vitest/ui": "^2.1.1",
"autoprefixer": "^10.4.20",
"git-cliff": "^2.5.0",
"happy-dom": "^15.7.4",
"lefthook": "^1.7.15",
"npm-check-updates": "^17.1.1",
"npm-check-updates": "^17.1.2",
"playwright": "^1.47.1",
"postcss": "^8.4.47",
"rollup-plugin-visualizer": "^5.12.0",
"storybook": "^8.3.0",
"storybook": "^8.3.1",
"tailwind-debug-breakpoints": "^1.0.3",
"tailwindcss-animate": "^1.0.7",
"tailwindcss": "^3.4.11",
"tailwindcss": "^3.4.12",
"typescript": "^5.6.2",
"vite-plugin-inspect": "^0.8.7",
"vite-tsconfig-paths": "^5.0.1",
"vite": "^5.4.5",
"vite": "^5.4.6",
"vitest": "^2.1.1"
},
"engines": {
Expand Down
Loading

0 comments on commit 561202d

Please sign in to comment.