Middle+
How to implement showing a banner once for an authorized user on all their devices?
sobes.tech AI
Answer from AI
To show a banner once for an authorized user on all their devices, it is necessary to store information on the server that the banner has already been shown, linked to the user's account.
Algorithm:
- When the application or page loads, the frontend makes a request to the server to find out whether the banner needs to be shown.
- The server checks a flag in the database, for example
bannerShown, for this user. - If the banner has not been shown, the server returns information that the banner should be displayed.
- After the user sees the banner, the frontend sends a request to the server to set the
bannerShown = trueflag for this user.
Thus, on the next visit from any device, the server will already know that the banner does not need to be shown.
API example:
- GET
/api/user/banner-status→{ "showBanner": true } - POST
/api/user/banner-shown→ sets the flag
This solution requires the user to be authenticated, and the frontend must be able to identify the user for requests.
Additionally, the status can be cached on the client to reduce the number of requests, but the main storage should be on the server.