TypeError: Cannot destructure property 'token' of 'req.cookie' as it is undefined. at authenticateToken (/Users/joey/WebstormProjects/mini_project_subwayLocker/middleware/authenticateToken.js:7:11) at Layer.handle [as handle_request] (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/layer.js:95:5) at next (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/route.js:144:13) at Route.dispatch (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/route.js:114:3) at Layer.handle [as handle_request] (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/layer.js:95:5) at /Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/index.js:284:15 at Function.process_params (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/index.js:346:12) at next (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/index.js:280:10) at Function.handle (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/index.js:175:3) at router (/Users/joey/WebstormProjects/mini_project_subwayLocker/node_modules/express/lib/router/index.js:47:12)const {token} = res.cookie;
첫 번째 시도 : 검색해서 찾은 결과 https://stackoverflow.com/questions/71636021/cannot-destructure-property-token-of-req-cookie-as-it-is-undefined-nodejs
const { token } = req.cookies['token'];
console.log(token)
결과 : undefined
쿠키에는 담겨 있는데 undefined 라는 로그를 출력
두 번째 시도
1. req.cookies 확인
const token = req.cookies;
console.log(token)
결과 { token : 입력된 토큰 값 } 출력
const token = req.cookies['token'];
console.log(token)
결과: 입력된 토큰 값 출력됨
해결!!