Skip to main content

Web SDK API V1 and V2 Compatibility Issue

CloudBase Web SDK API V1 and V2 versions are not interoperable, and mixing them will cause login errors.

Problem Description

When you use both Web SDK API V1 and V2 in the same project, you may encounter the following errors:

  • Console shows v1 sign in error
  • Users cannot log in normally
  • Database access failures

Root Cause

Web SDK API V1 and V2 are two independent versions with incompatible authentication mechanisms, session management, and calling methods:

  • After logging in with V1 SDK, you cannot use V2 SDK to call APIs
  • After logging in with V2 SDK, you cannot use V1 SDK to call APIs

The calling methods and session management mechanisms of the two versions are completely different and cannot be mixed.

Solutions

V2 SDK is the latest version with more complete features. Recommended for new projects.

// Initialize V2 SDK
import cloudbase from '@cloudbase/js-sdk';

const app = cloudbase.init({
env: 'your-env-id'
});

// Login
const auth = app.auth();
await auth.anonymousAuthProvider().signIn();

// Call database
const db = app.database();
const result = await db.collection('users').get();

Solution 2: Use V1 SDK Uniformly

If your existing project uses V1 SDK, you can continue using it, but do not mix versions.

// Initialize V1 SDK
import cloudbase from '@cloudbase/js-sdk/dist/cloudbase.js';

const app = cloudbase.init({
env: 'your-env-id'
});

// Login
await app.auth({
persistence: 'local'
});

// Call database
const db = app.database();
const result = await db.collection('users').get();

Solution 3: Project Migration

If you need to migrate from V1 to V2, refer to the official documentation for complete migration:

Important Notes

  1. Do Not Mix: Do not use both V1 and V2 SDKs in the same project
  2. Maintain Consistency: All modules (database, storage, cloud functions, etc.) should use the same SDK version
  3. Independent Sessions: V1 and V2 login sessions are independent and cannot be shared