-
Notifications
You must be signed in to change notification settings - Fork 58
Description
const isAuthenticatedUser = async (req, res, next) => {
const session = await getSession({req} );
if (!session) {
return next(new Error("Login first to access this route", 401));
}
req.user = session.user;
console.log( req.user = session.user);
next();
};
export { isAuthenticatedUser };
handel.use(isAuthenticatedUser).post(PostTodo)
handel.use(isAuthenticatedUser).get(getTodo)
[next-auth][error][CLIENT_FETCH_ERROR]
https://next-auth.js.org/errors#client_fetch_error undefined {
error: {},
url: 'http://localhost:3000/api/auth/session',
message: undefined
}
{
_id: '64443c6eb3d7f41520ad196f',
name: 'badhon',
email: '[email protected]',
password: '$2a$10$PMu0LvTsIDuArfbfcsb2HOH1KTDNgqmwMpcrmvSg9bK8UgIwQA8VW',
__v: 0
}
message ////////////////////////////
when I get request its proper work but when I post request on my formdata then getting error I am still login message is "Login first to access this route" why
like [next-auth][error][CLIENT_FETCH_ERROR]
console.log( req.user = session.user)
{
_id: '64443c6eb3d7f41520ad196f',
name: 'badhon',
email: '[email protected]',
password: '$2a$10$PMu0LvTsIDuArfbfcsb2HOH1KTDNgqmwMpcrmvSg9bK8UgIwQA8VW',
__v: 0
}