project_mern_memories
project_mern_memories copied to clipboard
req.userId = decodedData ? .id;
This (req.userId = decodedData ? .id;) line is producing error in middleware auth.js. When I remove the ternary operator and do (req.userId = decodedData .id;), it works. Any idea or knowledge about this ?
file:///E:/webdevelpoment/PracticeCodes/FullAuthBlog/server/middleware/auth.js:10 req.userId = decodedData ? .id; ^
SyntaxError: Unexpected token '.' at Loader.moduleStrategy (internal/modules/esm/translators.js:122:18) [nodemon] app crashed - waiting for file changes before starting...
I'm having the same issue.
Hey , you have to write like this : req.userId = decodedData?.id; There shouldn't be any spaces between ? and .
This (req.userId = decodedData ? .id;) line is producing error in middleware auth.js. When I remove the ternary operator and do (req.userId = decodedData .id;), it works. Any idea or knowledge about this ?
Were you able to fix this problem??
Hello, Yes I was able to do that. Please don't give any spaces. Just write decodedData?.id;
On Thu, Jul 22, 2021, 10:22 PM Denis Ouma @.***> wrote:
This (req.userId = decodedData ? .id;) line is producing error in middleware auth.js. When I remove the ternary operator and do (req.userId = decodedData .id;), it works. Any idea or knowledge about this ?
Were you able to fix this problem??
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_mern_memories/issues/30#issuecomment-885063069, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL3PXNYTL4SJF6TLQH4QFZDTZBEDXANCNFSM43RFF6VQ .
If not, then I will share my GitHub repo, you can have a look there.
On Sat, Jul 24, 2021, 12:59 PM VIBHU PARMAR @.***> wrote:
Hello, Yes I was able to do that. Please don't give any spaces. Just write decodedData?.id;
On Thu, Jul 22, 2021, 10:22 PM Denis Ouma @.***> wrote:
This (req.userId = decodedData ? .id;) line is producing error in middleware auth.js. When I remove the ternary operator and do (req.userId = decodedData .id;), it works. Any idea or knowledge about this ?
Were you able to fix this problem??
— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/adrianhajdin/project_mern_memories/issues/30#issuecomment-885063069, or unsubscribe https://github.com/notifications/unsubscribe-auth/AL3PXNYTL4SJF6TLQH4QFZDTZBEDXANCNFSM43RFF6VQ .
Did anyone manage to fix it? Unfortunately, getting rid of the spaces didn't solve the problem.
it work on my other machine i don't know why it broken now
Hello everyone, we can use (req.userId = decodedData;) in both cases of if and else .it works fine and doesn't give you error.
Hi! Could you solve it? I have the same problem.
yeah ,i am sharing snippet of code
if(token && isCustomAuth){ decodedData = jwt.verify(token,'test');
req.userId = decodedData;
}else{
decodedData = jwt.decode(token);
req.userId = decodedData;
}