From b1e5530294eac93eebc244cf28b55c9407eb53f3 Mon Sep 17 00:00:00 2001 From: Kenny Ki Date: Thu, 4 Sep 2014 13:47:17 +0800 Subject: [PATCH] Added example of handling token expiration --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 9f9696c..bd1e553 100644 --- a/README.md +++ b/README.md @@ -78,6 +78,29 @@ var socket = io.connect('http://localhost:9000', { }); ``` +## Handling token expiration + +__Server side__: + +When you sign the token with an expiration time: + +```javascript +var token = jwt.sign(user_profile, jwt_secret, {expiresInMinutes: 60}); +``` + +Your client-side code should handle it as below. + +__Client side__: + +```javascript +socket.on("error", function(error) { + if (error.type == "UnauthorizedError" || error.code == "invalid_token") { + // redirect user to login page perhaps? + console.log("User's token has expired"); + } +}); +``` + ## Contribute You are always welcome to open an issue or provide a pull-request!