The requirement you want to achieve should be unique login. It can be handled like this, request the login interface, generate a random string, store it in KV, and set the expiration time. This will only be triggered when logging in. Assume your account is abc, and the random string is 123456, cache.set('user:abc', '123456'). Each subsequent interface request carries a random string, which is compared with the random string corresponding to the user in the cache. If the random string has changed. Then you must have logged in again. It is necessary to force offline. Otherwise, refresh the expiration time of the random string. This does not affect efficiency because the cache will not cause an IO bottleneck.
The only login should be controlled by the background session. Specifically, the login ID is stored in the session, such as session["user"], that is, session["user"]= is set in the background when logging in. $loginUser ($loginUser is the login account name variable obtained from the front end, I use php as an example). This way, it always corresponds to this user during the user's visit. How to change to another user, session["user"] will become the id of another user, so the first user's session will be interrupted. This ensures that only one user can log in to a browser at the same time.
Before opening the page, first check whether there is a local COOKIE or localStorage in the browser. If so, use this information to log in automatically. Otherwise, a login box will pop up to allow them to log in or access anonymously
The requirement you want to achieve should be unique login.
It can be handled like this, request the login interface, generate a random string, store it in KV, and set the expiration time. This will only be triggered when logging in. Assume your account is abc, and the random string is 123456, cache.set('user:abc', '123456'). Each subsequent interface request carries a random string, which is compared with the random string corresponding to the user in the cache. If the random string has changed. Then you must have logged in again. It is necessary to force offline. Otherwise, refresh the expiration time of the random string. This does not affect efficiency because the cache will not cause an IO bottleneck.
The cookie or session on the backend should be able to guarantee a unique user. You can learn about cookies and sessions.
The only login should be controlled by the background session. Specifically, the login ID is stored in the session, such as session["user"], that is, session["user"]= is set in the background when logging in. $loginUser ($loginUser is the login account name variable obtained from the front end, I use php as an example). This way, it always corresponds to this user during the user's visit. How to change to another user, session["user"] will become the id of another user, so the first user's session will be interrupted. This ensures that only one user can log in to a browser at the same time.
Before opening the page, first check whether there is a local COOKIE or localStorage in the browser. If so, use this information to log in automatically. Otherwise, a login box will pop up to allow them to log in or access anonymously