N
N
Night_Harpy2021-01-17 18:06:01
Node.js
Night_Harpy, 2021-01-17 18:06:01

What should be passed to the token?

const result = jwt.verify(token, 'secret');
gives jwt malformed error. The problem seems to be in the token. what should be included in the token? do it via postman60045240e0c2d467490206.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
iredoff, 2021-01-17
@iredoff

If you use jwt, then it is immediately clear that you need to insert an active session token

P
Pavel, 2021-01-17
@PAVLIK_GYRA

For example. Authorization page for example /login/ should return a token

const token = jwt.sign(
          { userId: id },
          config.get('jwtSecret'),
          { expiresIn: '24h' }
        )
        res.json({ token })

You receive it on the client and write it to localStorage. When you need it, take it from there and insert it into the fetch or axios options {headers:{Authorization: token}} - for frontend
For postman you need a token and you can take it if you have implemented authorization with jwt

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question