Skip to main content

cloudbase js sdk version migration

v3 to v4 migration​

PostgreSQL, Cloud Storage, Cloud Functions, and Realtime keep the same usage as the v3 PostgreSQL reference. Authentication now defaults to the GoTrue client (app.auth()):

  • Sign-in identifiers are email or phone. Password sign-in no longer accepts username.
  • signUp and signInWithOtp no longer return a data.verifyOtp callback. After sign-up or sending a code, call verifyOtp.
  • auth.detectSessionInUrl is on by default and restores the session after a redirect. Set it to false to turn that off. The default flow is implicit, and the session is in the URL hash. For PKCE, set auth.flowType: 'pkce'. When automatic detection is on, do not call exchangeCodeForSession.
  • Change a password with updateUser. resetPasswordForOld is gone.
  • signInWithCustomTicket now takes { ticket }. v3 passed a function that returned the ticket.
  • createTicket works the same as in v3. Pass the private key in the top-level init credentials as private_key, private_key_id, and env_id. Node.js only.
  • signInWithOpenId now takes code and appId. The caller runs wx.login. CloudBase passwordless login can omit code. useWxCloud is no longer accepted.
  • signInWithPhoneAuth now takes phoneCode and appId. The AppID is no longer read from wx.getAccountInfoSync, and useWxCloud is no longer accepted.
  • These methods are not on the v4 client: toDefaultLoginPage, refreshUser, deleteUser, and the Node.js methods getUserInfo, getEndUserInfo, queryUserInfo, and getClientIP.
  • New methods: signInWithSSO, exchangeCodeForSession.

See Authentication.

Deprecated modules left unmounted​

These three modules are deprecated. Installing @cloudbase/js-sdk does not install their packages. To keep the old calls working, install each package, import its register function, then call init. app.database(), app.mysql(), and app.rdb() still ship with the main package.

ModuleCallInstallImport
Document realtimecollection.watch()@cloudbase/realtimeregisterRealtime
Data modelsapp.models@cloudbase/modelregisterModel
HTTP APIapp.apis@cloudbase/apisregisterApis
npm install @cloudbase/realtime @cloudbase/model @cloudbase/apis -S
import cloudbase from "@cloudbase/js-sdk";
import { registerRealtime } from "@cloudbase/realtime";
import { registerModel } from "@cloudbase/model";
import { registerApis } from "@cloudbase/apis";

registerRealtime(cloudbase);
registerModel(cloudbase);
registerApis(cloudbase);

collection.watch() comes from @cloudbase/realtime. app.realtime() comes from registerRealtimeJs in the main package. See Deprecated modules left unmounted.

v2 to v3 migration​

v3 is fully compatible with v2 in code usage and allows smooth migration, but note the following adjustments:

Relationship with login authentication

v1 to v2 migration​

Login authentication​

From v1 to v2, the login authentication module has the following adjustments:

-Login status persistence: Login status supports only local mode. -v2 no longer supports listening to user login status changes -v2 no longer supports WeChat Official Account login method. If you need to use this method, use v1 version. -Streamlined user field info. See User for details. -The account association usage method has been adjusted and no longer supports custom login association. For details, see "Authentication v2 | Account Association" -The login method has been adjusted. For details, see "Login Authentication v2 | Login Authentication".

API adjustment​

Auth​

Update​
  • API name typo fix: do not use Auth.getCurrenUser(). Use auth.getUser().
New feature​
Deprecated​
  • Auth.anonymousAuthProvider
  • Auth.customAuthProvider
  • Auth.forceResetPwdByPhoneCode
  • Auth.getAuthHeader
  • Auth.getAuthHeaderAsync
  • Auth.onAccessTokenRefreshed
  • Auth.onAnonymousConverted
  • Auth.onLoginStateExpired
  • Auth.onLoginTypeChanged
  • Auth.sendPasswordResetEmail
  • Auth.sendPhoneCode
  • Auth.shouldRefreshAccessToken
  • Auth.signInWithEmailAndPassword
  • Auth.signInWithPhoneCodeOrPassword
  • Auth.signInWithUsernameAndPassword
  • Auth.signUpWithEmailAndPassword
  • Auth.signUpWithPhoneCode
  • Auth.weixinAuthProvider

LoginState​

Deprecated​
  • LoginState.isAnonymousAuth
  • LoginState.isCustomAuth
  • LoginState.isUsernameAuth
  • LoginState.isWeixinAuth
  • LoginState.loginType

User​

Deprecated​
  • User.avatarUrl
  • User.linkWithPhoneNumber
  • User.nickName
  • User.updateEmail
  • User.updatePassword
  • User.updatePhoneNumber
  • User.updateUsername