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 inerror - 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
Solution 1: Use V2 SDK Uniformly (Recommended)
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
- Do Not Mix: Do not use both V1 and V2 SDKs in the same project
- Maintain Consistency: All modules (database, storage, cloud functions, etc.) should use the same SDK version
- Independent Sessions: V1 and V2 login sessions are independent and cannot be shared