In my project that I created using nextjs, I want the session to list while I make a listing query on the backend. If there is no session, I want it not to give authorized permission. I am using next authentication. I can't pull next in session But I can't get session. Can you help me, please?
Offers.belongsTo(Users, {as: 'User', foreignKey: 'user_id'});
router.post('/api/logistic/offers/get-offers', async (req, res) => {
const {limit, page, sortColumn, sortType, search, session} = req.body;
if(session){
const total = await Offers.findAll();
const offersList = await Offers.findAll({
limit: limit,
offset: (page - 1) * limit,
order: [
[sortColumn, sortType]
],
where: {
[Op.or]: [
{
offers_no: {
[Op.substring]: [
search
]
}
},
{
agreement_date: {
[Op.substring]: [
search
]
}
},
{
routes: {
[Op.substring]: [
search
]
}
},
{
type_of_the_transport: {
[Op.substring]: [
search
]
}
},
]
},
include: [{
model: Users,
as: 'User'
}]
});
res.json({
total: total.length,
data: offersList
});
}else {
res.status(401).send(JSON.stringify({
status: "error",
title: 'Unauthorized',
message: 'Unauthorized'
}));
}
})
The error I get in the terminal is always like this. I can't use session
//offers list
Offers.belongsTo(Users, {as: 'User', foreignKey: 'user_id'});
router.post('/api/logistic/offers/get-offers', async (req, res) => {
const session = await getSession({req});
console.log(session);
if(session){
const {limit, page, sortColumn, sortType, search} = req.body;
const total = await Offers.findAll();
const offersList = await Offers.findAll({
limit: limit,
offset: (page - 1) * limit,
order: [
[sortColumn, sortType]
],
where: {
[Op.or]: [
{
offers_no: {
[Op.substring]: [
search
]
}
},
{
agreement_date: {
[Op.substring]: [
search
]
}
},
{
routes: {
[Op.substring]: [
search
]
}
},
{
type_of_the_transport: {
[Op.substring]: [
search
]
}
},
]
},
include: [{
model: Users,
as: 'User'
}]
});
res.json({
total: total.length,
data: offersList
});
}else {
res.status(401).send(JSON.stringify({
status: "error",
title: 'Unauthorized',
message: 'Unauthorized'
}));
}
})
This is how my code was before. but it didn't work.
