Best Practices
Preventing Duplicate Logins
Before executing the login process, we highly recommend that you first determine whether the client has already logged in to CloudBase. If already logged in, there is no need to execute the login process to avoid meaningless duplicate logins.
- Web
const auth = app.auth();
// On application initialization
if (auth.hasLoginState()) {
// Already logged in
} else {
// Not logged in, execute your login process
}
Persistent Retention of Login Status
You can specify how the login state persists. The default is local
, and the available options include:
Value | Description |
---|---|
session | Retains the login state in SessionStorage, which will be cleared after the current page is closed. |
local | Retains the login state persistently in local storage. |
none | Retains the login state in memory, which will be cleared after page refresh or redirection. |
For example, for web applications, the best choice is local
, which retains the user's session after the browser is closed. This way, users do not need to log in repeatedly every time they visit the page, avoiding inconvenience to them.
- Web
const auth = app.auth({
persistence: "local"
});