i am using js sdk of kuzzle, sometimes (after few days of running) all request fails and i get: "Insufficient permissions to execute this action" what's the best method to avoid it ? Should i check the jwt token is still valid before request ? or how to get notified of token expiration (i set it to 1 year) ?
This error message indicate that your current user does not have the permissions to execute this API action. The error message is different when the anonymous user (default user when you are not authenticated) try to execute an API action that's need to be authenticated.
See the differences between error 401 and 403 here
About your authentication token, it's considered as a bad practice to have an authentication token that last a long period of time. (Even if Kuzzle authentication token can be revoked).
You should rather use the auth:refreshToken method to regularly refresh your authentication token)
Actually Kuzzle send a notification indicating that the current token is expired only when a subscription has been made to the realtime engine. This will certainly be extended to any persistent connection made to Kuzzle in a next release.
Concerning your usecase, you may want to use an API key to authenticate your SDK instance. There are revocable and can have infinite duration.