Empty values are being mistakenly assigned to cookies in a production environment within Next.js

My struggle lies in setting cookies with the cookies function within Next.js. While everything works smoothly on localhost, the production environment seems to render empty cookie values. The peculiar thing is that these cookies are being set by the Next.js server itself. This is how I am going about it:

const cookieStore = cookies();

cookieStore.set({
  name: "accessToken",
  value: res.data?.google?.access,
  httpOnly: true,
  secure: true,
  path: "/",
  maxAge: 3600,
  expires: new Date(Date.now() + 3600),
  sameSite: "strict",
});

cookieStore.set({
  name: "refreshToken",
  value: res.data?.google?.refresh,
  httpOnly: true,
  secure: true,
  path: "/",
  maxAge: 7 * 24 * 60 * 60,
  expires: new Date(Date.now() + 7 * 24 * 60 * 60),
  sameSite: "strict",
});

Despite attempting various solutions such as those found in Client not saving cookies in production, Cookies are not being set in production, and Cookies Not Being Set in Production in Next.js App, none have proven effective in resolving my issue.

As a side note, my setup involves using Next.js V15 rc.

Answer №1

My assumption is that the issue stems from setting the cookies prior to receiving the response.

It's worth attempting to transform this into:

secure: process.env.NODE_ENV === 'production'

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Can the PKCE flow with okta-react be configured to store the okta-token-storage in cookies instead of local storage? If so, how can

In order to comply with our organizational policy, I have successfully implemented the PKCE flow using the @okta/okta-react library. However, after a successful login, the accessToken and idToken are currently being stored in local storage instead of cooki ...

Unable to precisely reach the very bottom of the scrollbar

When trying to move to the bottom of the scrollbar, I seem to reach a bit higher than the actual bottom. https://i.stack.imgur.com/Vt83t.png Here is my code: ws.onmessage = function (event) { var log = document.getElementById('log') ...

Difficulty Communicating Recapcha 2 with the PHP Script

I am currently testing the installation of reCaptcha 2 with server-side verification using a form with one input field. My process involves sending the reCaptcha response via Ajax to a PHP page for verification. While I am able to capture the information p ...

Having trouble retrieving information from a nested JSON array within a JSON object using JavaScript

I am facing a challenge with extracting specific information from a JSON object that contains an array nested inside. Even though I have experience working with JSON arrays, this particular object is proving to be tricky. For example, when attempting to r ...

Is there a way to automatically play videos without any audio?

Is there a way for my video to automatically start playing when the page loads, without sound? I want it to function similar to the video on this webpage: . I've experimented with various jQuery, JavaScript, and CSS techniques from online resources, ...

Got any ideas for Laravel 8's One to One messaging feature?

I am looking to create a real-time one-to-one messaging system for the users of my application. I anticipate around 10,000 users. Instead of utilizing web sockets or similar solutions, I am currently using Livewire for other features. My initial thought wa ...

Invoke a function within the redux reducer

The code within my reducer is structured as follows: import {ADD_FILTER, REMOVE_FILTER} from "../../../../actions/types"; const removeFilter = (state, name) => { return state.filter(f => f.name !== name); }; export default function addRemoveFi ...

The challenge of synchronizing Javascript and PHP code

I am trying to trigger a JavaScript function with parameters retrieved from MySQL and have it execute on an onClick event. Below is the JavaScript code that I am using: function getFile() { if (window.XMLHttpRequest) { AJAX=new XM ...

Switching picture using dropdown menu in javascript/jquery

Having some trouble trying to recreate this example. The initial image shows up, but it doesn't change when I select a different option. Still getting the hang of javascript so any help is appreciated. <html> <head> <script src="/j ...

What is the method employed by Node.js to manage relative paths?

I am facing an issue with how Node.js handles paths. Despite checking the documentation, I couldn't find the solution to my problem. Basically, I have a file that contains a relative path pointing to another file (specifically a PNG image). Dependin ...

Is there a way to retrieve the transaction specifics for the initial 50 clients from a MongoDB database?

In my PC's local server, there is a cluster with approximately 240,000 entries of transaction data. The abbreviation Cust_ID represents Customer ID. https://i.sstatic.net/5g65l.png Each file contains transactions made by different customers, with a ...

Add both single (' ') and double (" ") quotes within the `document.querySelector` code

Given an array of attributes like the following: let elementsArray = [ '[name="country_code"]', '[name="user_tel_code"]', '[name="countryCode"]' ]; If I aim to iterate through them using a ...

Challenges with transitions and transformations across different web browsers

I've encountered some difficulties while working on my new website. The mobile navigation menu is supposed to appear when the browser window is below 940px wide. It functions properly on Chrome and other webkit browsers, but in Firefox and IE, the tr ...

Using Jquery to detect changes in a Datalist element in an HTML5 document

This snippet illustrates the code: <input name="cmbname" type="text" id="cmbname" list="listcmbname" autocomplete="off" runat="server"> <datalist id="listcmbname"> <option data-id="1" value="a"></option> <optio ...

Node.js: Extracting parameters from the URL

When working with Rails, I make a POST request to my server: response = Typhoeus::Request.post("http://url.localtunnel.com/request?from=ola&to=ole") result = JSON.parse(response.body) Now in my Node.js application, I need to retrieve values for From ...

Angular's directives do not trigger the 'viewContentLoaded' event

I recently created a 'light-gallery' directive that relies on the jquery.lightgallery.js plugin to initialize the $.fn.lightGallery() functions. It is crucial for these functions to be executed after the directive template has been compiled and l ...

Creating a Future Prediction Graph with ECharts

I am looking to create a forecast chart that includes both Actual values (presented as a line chart) and projected values (displayed as a dotted chart). An example of what I have in mind can be seen here, created using Excel: https://i.sstatic.net/q18An.pn ...

Changing the Material UI imported Icon on click - a step-by-step guide

Hey there, I'm currently working with React JS and Redux. I have a challenge where I need to change the star outline icon to a filled star icon on click. The icon is located just after emailRow in the emailRow__options section. Can someone assist me w ...

Troubleshooting: Issues with Form Parameters in JSP

Here is the HTML form I am working with: <form action="supplierportal_home.jsp"> <select id="contract" name="contract"> <option selected="selected">Please Select</option> <option value="open" >Open</ ...

Can this route protection solution be trusted for use in Next.js?

import { useEffect, useState } from 'react'; import { useRouter } from 'next/router'; import Login from './index'; import auth from '../services/authService'; export default function App({ Component, pageProps }) { ...