Skip to content

Commit

Permalink
fix: Set secure cookie options accordingly to stop Safari from discar…
Browse files Browse the repository at this point in the history
…ding cookies in localhost (#11)
  • Loading branch information
cwerl authored Oct 13, 2024
1 parent 2509e49 commit 5e65c62
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
7 changes: 6 additions & 1 deletion frontend/src/lib/actions/auth.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use server'

import { isProduction } from '@/lib/utils'
import { ApiResponse, AppSession, AppSessionData } from '@/types'
import { IronSession, getIronSession } from 'iron-session'
import { getIronSession, IronSession } from 'iron-session'
import { decodeJwt } from 'jose'
import { cookies } from 'next/headers'
import { redirect } from 'next/navigation'
Expand All @@ -10,6 +11,10 @@ export async function getAppSession(): Promise<IronSession<AppSession>> {
return getIronSession<AppSession>(cookies(), {
password: process.env.APP_SECRET as string,
cookieName: 'intranet_session',
cookieOptions: {
secure: isProduction(),
sameSite: 'strict',
},
ttl: 60 * 60 * 24 * 7,
})
}
Expand Down
4 changes: 3 additions & 1 deletion frontend/src/lib/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ApiErrors, AppSessionData } from '@/types'
import { clsx, type ClassValue } from 'clsx'
import { type ClassValue, clsx } from 'clsx'
import { FieldValues, UseFormReturn } from 'react-hook-form'
import { twMerge } from 'tailwind-merge'

Expand Down Expand Up @@ -50,3 +50,5 @@ export async function urlToFile(url: string, filename: string): Promise<File> {
export function isCreator(sessionData?: AppSessionData): boolean {
return sessionData?.roles.includes('Creator') ?? false
}

export const isProduction = () => process.env.NODE_ENV === 'production'

0 comments on commit 5e65c62

Please sign in to comment.