How to destroy JWT Tokens on logout?

后端 未结 5 1656
[愿得一人]
[愿得一人] 2020-12-02 08:10

I am using jwt plugin and strategy in hapijs.

I am able to create jwt token while login user and authenticate other API using the same token through \'jwt\' strategy

5条回答
  •  暖寄归人
    2020-12-02 08:50

    While other answers provide detailed solutions for various setups, this might help someone who is just looking for a general answer.

    There are three general options, pick one or more:

    1. On the client side, delete the cookie from the browser using javascript.

    2. On the server side, set the cookie value to an empty string or something useless (for example "deleted"), and set the cookie expiration time to a time in the past.

    3. On the server side, update the refreshtoken stored in your database. Use this option to log out the user from all devices where they are logged in (their refreshtokens will become invalid and they have to log in again).

提交回复
热议问题