project_mern_memories icon indicating copy to clipboard operation
project_mern_memories copied to clipboard

req.userId = decodedData ? .id;

Open adityaFE opened this issue 3 years ago • 11 comments

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 ?

adityaFE avatar Apr 25 '21 11:04 adityaFE

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...

adityaFE avatar Apr 25 '21 11:04 adityaFE

I'm having the same issue.

jansoriano-dev avatar Jun 04 '21 09:06 jansoriano-dev

Hey , you have to write like this : req.userId = decodedData?.id; There shouldn't be any spaces between ? and .

VibhuGautam avatar Jul 10 '21 09:07 VibhuGautam

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??

DenisOuma avatar Jul 22 '21 16:07 DenisOuma

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 .

VibhuGautam avatar Jul 24 '21 07:07 VibhuGautam

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 .

VibhuGautam avatar Jul 24 '21 08:07 VibhuGautam

Did anyone manage to fix it? Unfortunately, getting rid of the spaces didn't solve the problem.

nikajerkovic avatar Aug 21 '21 16:08 nikajerkovic

it work on my other machine i don't know why it broken now

fharlup avatar Aug 29 '21 08:08 fharlup

Hello everyone, we can use (req.userId = decodedData;) in both cases of if and else .it works fine and doesn't give you error.

kalanaveen avatar Oct 03 '21 08:10 kalanaveen

Hi! Could you solve it? I have the same problem.

Mariana0317 avatar Oct 04 '21 19:10 Mariana0317

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;
    }

kalanaveen avatar Oct 05 '21 12:10 kalanaveen