I’m facing a problem with my express route, where the cookie that is sent as a response is not set on the client, the strange thing is that the cookie is sent in the header, but it doesn’t appear in the browser.
Here is the middlewares
app.use(cors());
app.use(morgan("tiny"));
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false, limit: "100kb" }));
app.use(cookieParser());
Here is my route
export const createUser = async (req: Request, res: Response) => {
try {
const { name, password, username, email } = req.body;
// Create a value to append before the password
const salt = await bcrypt.genSalt(15);
// Create a hash password
const hashedPassword = await bcrypt.hash(password, salt);
const user = await db.user.create({
data: {
name,
password,
username: hashedPassword,
email,
},
});
const session = await lucia.createSession(user.id, {});
const sessionCookie = lucia.createSessionCookie(session.id);
res
.status(StatusCodes.ACCEPTED)
.cookie(sessionCookie.name, sessionCookie.value)
.json({ sucess: true });
} catch (error) {
console.log(error);
res
.status(StatusCodes.INTERNAL_SERVER_ERROR)
.json({ sucess: false, error });
}
};
Here’s the header
As you can see, doesn’t appear in the client
I’m trying to define a cookie in the server and send to the client