mirror of
https://github.com/Thream/socketio-jwt.git
synced 2024-07-21 09:38:31 +02:00
Added example of handling token expiration
This commit is contained in:
parent
479d646374
commit
b1e5530294
23
README.md
23
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!
|
||||
|
Loading…
Reference in New Issue
Block a user