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. signUpandsignInWithOtpno longer return adata.verifyOtpcallback. After sign-up or sending a code, callverifyOtp.auth.detectSessionInUrlis on by default and restores the session after a redirect. Set it tofalseto turn that off. The default flow is implicit, and the session is in the URL hash. For PKCE, setauth.flowType: 'pkce'. When automatic detection is on, do not callexchangeCodeForSession.- Change a password with
updateUser.resetPasswordForOldis gone. signInWithCustomTicketnow takes{ ticket }. v3 passed a function that returned the ticket.createTicketworks the same as in v3. Pass the private key in the top-levelinitcredentialsasprivate_key,private_key_id, andenv_id. Node.js only.signInWithOpenIdnow takescodeandappId. The caller runswx.login. CloudBase passwordless login can omitcode.useWxCloudis no longer accepted.signInWithPhoneAuthnow takesphoneCodeandappId. The AppID is no longer read fromwx.getAccountInfoSync, anduseWxCloudis no longer accepted.- These methods are not on the v4 client:
toDefaultLoginPage,refreshUser,deleteUser, and the Node.js methodsgetUserInfo,getEndUserInfo,queryUserInfo, andgetClientIP. - 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.
| Module | Call | Install | Import |
|---|---|---|---|
| Document realtime | collection.watch() | @cloudbase/realtime | registerRealtime |
| Data models | app.models | @cloudbase/model | registerModel |
| HTTP API | app.apis | @cloudbase/apis | registerApis |
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:
- Identity verification, SCF, cloud storage request domain is changed to: {env}.api.tcloudbasegateway.com, aligning with the HTTP API.
- Cloud Storage uses PostgreSQL buckets. See Cloud Storage. -v3 optimizes the identity verification module, bringing more convenient API invocation operations. The new method is recommended. For usage, see Identity Verification.
- SCF, cloud storage domain name changes will involve pre open APIs permission validation. Visit Cloud Development Platform/Identity Verification/Permission Control to perform role association. For details, refer to Policy Management.
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(). Useauth.getUser().
New feature
- Auth.bindEmail
- Auth.bindPhoneNumber
- Auth.bindWithProvider
- Auth.deleteMe
- Auth.genProviderRedirectUri
- Auth.getAccessToken
- Auth.getProviders
- Auth.getUserInfo
- Auth.getVerification
- Auth.grantProviderToken
- Auth.loginScope
- Auth.queryUser
- Auth.resetPassword
- Auth.setCustomSignFunc
- Auth.setPassword
- Auth.signIn
- Auth.signInAnonymously
- Auth.signInWithCustomTicket
- Auth.signInWithOpenId
- Auth.signInWithPhoneAuth
- Auth.signInWithProvider
- Auth.signInWithSms
- Auth.signInWithEmail
- Auth.signInWithUnionId
- Auth.signUp
- Auth.sudo
- Auth.unbindProvider
- Auth.verify
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