Skip to content

Commit

Permalink
fix: encode cookies for non-develpment environment
Browse files Browse the repository at this point in the history
  • Loading branch information
riipandi committed Sep 19, 2024
1 parent 00df2a8 commit 8ff380f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
3 changes: 2 additions & 1 deletion app/context/providers/theme-provider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function useThemeEffect(theme: ThemeType | null) {
const { revalidate } = useRevalidator()
const persistTheme = useFetcher()

// FIXME glitch on first load in dark mode
const setThemeClass = useCallback((newTheme: ThemeType) => {
document.documentElement.classList.remove(Theme.LIGHT, Theme.DARK)
document.documentElement.classList.add(newTheme)
Expand All @@ -43,7 +44,7 @@ function useThemeEffect(theme: ThemeType | null) {
const resolvedTheme = theme === Theme.SYSTEM ? getTheme() : theme
setThemeClass(resolvedTheme)
}
}, [theme])
}, [theme, setThemeClass])

useEffect(() => {
const mediaQuery = window.matchMedia(prefersLightMQ)
Expand Down
6 changes: 4 additions & 2 deletions app/utils/env.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ export const GlobalCookiesOptions: Omit<CookieOptions, 'name' | 'expires'> = {
secrets: process.env.NODE_ENV !== 'development' ? [process.env.APP_SECRET_KEY] : [],
encode: (val) => {
try {
return atob(val) // Decode the Base64 cookie value
// Decode the Base64 cookie value in development mode
return process.env.NODE_ENV === 'development' ? atob(val) : val
} catch (error) {
logger.error('Failed to encode cookie:', error)
return val // Return original value if encoding fails
}
},
decode: (val) => {
try {
return btoa(val) // Encode the cookie value to Base64
// Encode the cookie value to Base64 in development mode
return process.env.NODE_ENV === 'development' ? btoa(val) : val
} catch (error) {
logger.error('Failed to decode cookie:', error)
return val // Return original value if decoding fails
Expand Down
13 changes: 11 additions & 2 deletions biome.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,24 @@
"noCommentText": "off",
"noConsoleLog": {
"level": "info",
"fix": "none"
"fix": "safe"
},
"noDebugger": "off",
"noExplicitAny": "off",
"noConsole": {
"level": "warn",
"fix": "none",
"options": {
"allow": ["assert", "error", "info", "warn", "debug"]
"allow": [
"assert",
"error",
"info",
"warn",
"debug",
"time",
"timeEnd",
"timeLog"
]
}
},
"noDuplicateAtImportRules": "error",
Expand Down

0 comments on commit 8ff380f

Please sign in to comment.