How to ensure the unity of login session in js project

We are Mini Program"s project. To get the code logged in by Wechat, request the backend api to get the sessionkey. But if it is a concurrent request, if it happens to expire at this time, and several requests go to get the sessionkey at the same time, the subsequent request will expire the sessionkey obtained by the previous request, so how to ensure the unity of session?

Feb.27,2021

the data structure returned by each request is uniform, including sessionkey (hereinafter referred to as key):
1.) When there is no expired key request, return this key;
2. When key has expired, return the new key;
3. When a new key request is made, return the new key;
4. When you take a key request that does not exist, go back to the login process (or the correction process for verifying the status of the account);
5. The front end automatically stores the key acquired each time into the local cache;
6. The key is fetched from the local cache when requested.

therefore, it is recommended that the server store an old key, and a current new key on two key.

Menu