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 or login session expired, execute your login process
}

Persistent Retention of Login Status

The @cloudbase/js-sdk@2.xversion has removed support forsessionandnonelogin states, now only supportinglocal` state which persistently stores login status in local storage. This means session information remains preserved even when users close their browsers. This eliminates the need for repeated logins during each visit to the web application, avoiding numerous inconveniences.

For specific differences, please refer to the V1 Auth object