File tree Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Expand file tree Collapse file tree 2 files changed +10
-2
lines changed Original file line number Diff line number Diff line change @@ -106,7 +106,12 @@ export function AuthProvider({ children }: AuthProviderProps) {
106106 setUsername ( data . username ) ;
107107
108108 // Check auth again to get expiration time
109- await checkAuth ( ) ;
109+ // Add a small delay to ensure the httpOnly cookie is available
110+ await new Promise < void > ( ( resolve ) => {
111+ setTimeout ( ( ) => {
112+ void checkAuth ( ) . then ( ( ) => resolve ( ) ) ;
113+ } , 150 ) ;
114+ } ) ;
110115 return true ;
111116 } else {
112117 const errorData = await response . json ( ) ;
Original file line number Diff line number Diff line change @@ -47,10 +47,13 @@ export async function POST(request: NextRequest) {
4747 username
4848 } ) ;
4949
50+ // Determine if request is over HTTPS
51+ const isSecure = request . url . startsWith ( 'https://' ) ;
52+
5053 // Set httpOnly cookie with configured duration
5154 response . cookies . set ( 'auth-token' , token , {
5255 httpOnly : true ,
53- secure : process . env . NODE_ENV === 'production' ,
56+ secure : isSecure , // Only secure if actually over HTTPS
5457 sameSite : 'strict' ,
5558 maxAge : sessionDurationDays * 24 * 60 * 60 , // Use configured duration
5659 path : '/' ,
You can’t perform that action at this time.
0 commit comments