Skip to main content

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.

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:

ValueDescription
sessionRetains the login state in SessionStorage, which will be cleared after the current page is closed.
localRetains the login state persistently in local storage.
noneRetains 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.

const auth = app.auth({
persistence: "local"
});