not getting req.cookies (cookie ) in express.js

I’m working on an Express.js application and I’m having trouble accessing cookies from incoming requests. cookies in the browser, req.cookies is always [Object: null prototype] {} but alredy cookie having in browser. Here are the steps I’ve taken and for fetching api using redux-tookit-query for fetching API

Jobroute.js
 

const express = require("express");
const {AppliedCandidate,RejectedSingleCandidate,ShortlistCandidate} = require("../controllers/JobController");
const Verifyorg = require("../middlewares/Verifyorg");
const VerifyToken= require('../middlewares/verifytoken');

const router = express.Router()
router.get('/jobdetail/:id',VerifyToken,Verifyorg,AppliedCandidate);
router.patch('/reject/:applicationId/:candidateId',VerifyToken,Verifyorg, RejectedSingleCandidate);
router.put('/shortlist/:applicationId/:candidateId',Verifyorg , VerifyToken , ShortlistCandidate);

module.exports = router;

Already using this NPM packages :

cookie-parser is correctly installed

Main Index.js file code :

const express = require('express');
const app = express();
const cookieParser = require('cookie-parser');
const bodyParser = require('body-parser');
const cors = require('cors');
require('dotenv').config();
var morgan = require('morgan')
const port = process.env.PORT;
const errorHandler = require('./handler/errorhandler');
const fileUpload = require('express-fileupload');
const ConnectDB = require('./config/DbConfig');
app.use(cookieParser());

ConnectDB();

const corsOptions = {
  origin:'http://localhost:5173',
  credentials: true,
  methods: ["GET", "POST", "PUT", "DELETE","PATCH"],
  allowedHeaders: ["Content-Type", "Authorization"]
};

app.use((req, res, next) => {
  console.log(req.cookies);
  res.header('Access-Control-Allow-Origin', 'http://localhost:5173');
  next();

});
app.use(morgan('dev'));
morgan(':method :url :status :res[content-length] - :response-time ms')




app.use(cors(corsOptions));

app.use(express.json());
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(fileUpload({ limits: { fileSize: 5 * 1024 * 1024 }, useTempFiles: true }));



//Routes

const jobroutes = require('./routes/JobRoutes');
const Orgroutes = require('./routes/OrgRoute');
const Userroute = require('./routes/UserauthRoute');

app.use('/api/user', Userroute);
app.use('/api/org', Orgroutes);
app.use('/api/job', jobroutes);

app.use(errorHandler);

app.listen(port, () => {
  console.log(`server Listing on Port ${port}`);
});

verifytoken.js code here :

const jwt = require("jsonwebtoken");
const SECERET_KEY = process.env.JWT_SECRET;

const VerifyToken = async (req, res, next) => {
  try {
    const {accesstoken} = req?.cookies;



    if (!accesstoken) {
      return res.status(401).send({ message: 'Unauthorized user access' });
    }
    jwt.verify(accesstoken, SECERET_KEY, (err, decodedToken) => {
      if (err) {
        return res.status(403).send({ message: 'Invalid or expired token' });
      }else{
        req.user = decodedToken;
        next();
      }
    });
} catch (err) {

     return res.status(500).send({ message: err.message });
}
};


module.exports = VerifyToken

redux toolkit code :

import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';

export const jobApi = createApi({
  reducerPath: 'jobApi',
  baseQuery: fetchBaseQuery({ baseUrl: 'http://localhost:8800/api/job' }),
  refetchOnMountOrArgChange: true,
  tagTypes: ['job', 'org'],
  endpoints: (builder) => ({
    searchJobs: builder.query({
      query: (searchparams) => {
        console.log(searchparams);
        return {
          url: '/post/search',
          method: 'GET',
          params: searchparams,
          transformResponse: (jobs) => jobs.reverse(),
        };
      },
      providesTags: ['job'],
    }),
    getJobById: builder.query({
      query: (id) => `/getjob/${id}`,
      providesTags: ['job'],
    }),
    getJobcategory: builder.query({
      query: () => `/category`,
      invalidatesTags: ['job'],
    }),
    JobdetailWithCandidate: builder.query({
      query: (id) => `/jobdetail/${id}`,
      headers: { 'Content-Type': 'application/json' },
      credentials: 'include',
      invalidatesTags: ['job'],
    }),
    createJob: builder.mutation({
      query: (FormData) => ({
        url: '/create',
        method: 'POST',
        body: FormData,
        headers: { 'Content-Type': 'application/json' },
        credentials: 'include',
      }),
      invalidatesTags: ['job', 'org'],
    }),
    RejectedSingleCandidate: builder.mutation({
      query: ({ applicationId, candidateId }) => ({
        url: `/reject/${applicationId}/${candidateId}`,
        method: 'PATCH',
        credentials: 'include',
      }),
      invalidatesTags: ['job'],
    }),
  }),
});

export const {
  useGetJobcategoryQuery,
  useCreateJobMutation,
  useGetJobByIdQuery,
  useJobdetailWithCandidateQuery,
  useSearchJobsQuery,
  useRejectedSingleCandidateMutation,
} = jobApi;

export default jobApi;

// getJobs: builder.query({
//   query: () => '/getall/jobs',
//   providesTags: ["job"],
//   transformResponse: (jobs) => jobs.reverse(),
//   refetchOnMountOrArgChange: true,
// }),

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật