B
B
Bogdan2018-03-20 12:06:09
JavaScript
Bogdan, 2018-03-20 12:06:09

How to check if jwt is not lined?

Hello. Can you please tell me the best way to check if the jwt token that came from the server is not stitched? Thank you.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Z
ze7, 2018-03-20
@ze7

I think something like this:

...
 const token = ctx.headers['x-token'];

  if (token) {
    try {
      const { user } = jwt.verify(token, secretOne);
      ctx.user = user;
    } catch (err) {
      const refreshToken = ctx.headers['x-refresh-token'];
      const newTokens = await refreshTokens(
        token,
        refreshToken,
        secretOne,
        secretTwo
      );  
    }
  }
...

ps From the server or to the server? Can an expired one come from the server?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question