Having Trouble Storing Cookies from expressjs to the browser

46 Views Asked by At

i'am trying to store cookies from express js in the browser, they work fine on localhost but not after hoisting them (both frontend and backend are hosted in the same place render.com)

frontend : https://frontend.domain.com

import axios from "axios";

const api = axios.create({
  baseURL: "https://backend.domain.com",
  withCredentials: true,
});

export { api };

back-end : https://backend.domain.com

cookies.js :

exports.options = (maxAge) => {
    // return { domain: process.env.cors_origin, SameSite: "None", secure: true, httpOnly: true, maxAge: maxAge * 1000 }; this not work so i try to remove everything but still not work
    return { httpOnly: false, maxAge: maxAge * 1000 };
}; 

exports.create = (data, CustomMaxAge) => {
    ...
    return { token, defaultValue: exports.options(maxAge) };
};

router.js

const cookies = require("cookies.js");

const { token, defaultValue } = cookies.create(data, age);
res.cookie("cookie", token, defaultValue);
res.sendStatus(200);

server.js

app.use(cors({
    origin: process.env.cors_origin,
    credentials: true
}));

config.env

cors_origin=https://frontend.domain.com

it's look like i setup everything correctly but i can't find the cookies in the front-end and i can't read them from the back-end, (i don't mean to display the cookies on the frontend but find the cookies in the dev tool)

0

There are 0 best solutions below