@cloudbase/wx-cloud-client-sdk 1.8.0 → 1.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -18,7 +18,6 @@ import { init } from '@cloudbase/wx-cloud-client-sdk';
18
18
  // 使用微信云开发实例初始化
19
19
  const client = init(wx.cloud, {
20
20
  envId: 'your-env-id',
21
- accessKey: 'your-access-key', // 可选,客户端 Publishable Key
22
21
  });
23
22
  ```
24
23
 
@@ -117,11 +116,31 @@ const auth = client.auth;
117
116
  // 微信小程序 OpenID 静默登录,用户不存在则注册成外部注册用户
118
117
  await auth.signInWithOpenId();
119
118
 
119
+ // 更新用户信息
120
+ const { data, error } = await auth.updateUser({
121
+ nickname: '新昵称',
122
+ gender: 'MALE',
123
+ });
124
+
125
+ // 更新 email 或 phone(需要验证)
126
+ const { data, error } = await app.auth.updateUser({
127
+ email: 'new@example.com',
128
+ });
129
+
130
+ // 调用 verifyOtp 回调验证
131
+ await data.verifyOtp({ email: 'new@example.com', token: '123456' });
132
+
133
+ // 获取当前用户信息
134
+ const { data, error } = await auth.getUser();
135
+
120
136
  // 获取登录状态
121
- const { data } = auth.getSession();
137
+ const { data, error } = auth.getSession();
122
138
 
123
139
  // 登出
124
140
  await auth.signOut();
141
+
142
+ // 刷新登录状态
143
+ await auth.refreshSession();
125
144
  ```
126
145
 
127
146
  ## API
@@ -130,11 +149,19 @@ await auth.signOut();
130
149
 
131
150
  初始化 SDK(使用云函数调用)。
132
151
 
133
- | 参数 | 类型 | 必填 | 说明 |
134
- | ----------------- | ----------------- | ---- | ---------------------- |
135
- | cloud | CloudBaseInstance | 是 | 微信云开发实例 |
136
- | options.envId | string | 否 | 环境 ID |
137
- | options.accessKey | string | 否 | 客户端 Publishable Key |
152
+ | 参数 | 类型 | 必填 | 说明 |
153
+ | ------------- | ----------------- | ---- | -------------- |
154
+ | cloud | CloudBaseInstance | 是 | 微信云开发实例 |
155
+ | options.envId | string | 否 | 环境 ID |
156
+
157
+ ### 认证方法
158
+
159
+ - `signInWithOpenId()` - 微信小程序 OpenID 静默登录,用户不存在则注册成外部注册用户
160
+ - `updateUser(params)` - 更新用户信息
161
+ - `getUser()` - 获取当前用户信息
162
+ - `getSession()` - 获取登录状态
163
+ - `refreshSession()` - 刷新登录状态
164
+ - `signOut()` - 登出
138
165
 
139
166
  ### 数据模型方法
140
167
 
@@ -1,6 +1,4 @@
1
- import { CloudBaseInstance } from '../types';
2
- import { Auth } from '@cloudbase/auth';
1
+ import { CloudBaseInstance, Auth } from '../types';
3
2
  export declare const generateAuthClient: (cloud: CloudBaseInstance, options?: {
4
3
  envId?: string;
5
- accessKey?: string;
6
4
  }) => Auth;
package/lib/index.d.ts CHANGED
@@ -11,7 +11,6 @@ export declare function initHTTPOverCallFunction(cloud: CloudBaseInstance, optio
11
11
  }): ExtendedCloudBaseInstance;
12
12
  export declare function init(cloud: CloudBaseInstance, options?: {
13
13
  envId?: string;
14
- accessKey?: string;
15
14
  }): ExtendedCloudBaseInstance;
16
15
  declare function generateMySQLClient(cloud: CloudBaseInstance, options?: {
17
16
  envId?: string;
@@ -1,6 +1,6 @@
1
1
  import { SDKRequestInterface } from '@cloudbase/adapter-interface';
2
2
  import { MySqlClient } from '../db/mysql';
3
- import { Auth } from '@cloudbase/auth';
3
+ import { Auth as AuthInstance } from '@cloudbase/auth';
4
4
  /**
5
5
  * 基础 Model 类型定义
6
6
  */
@@ -717,6 +717,14 @@ export type CloudBaseInstance = {
717
717
  auth: any;
718
718
  };
719
719
  export type IMySqlClient = (options?: IMySqlOptions) => MySqlClient;
720
+ export interface Auth {
721
+ signInWithOpenId: AuthInstance['signInWithOpenId'];
722
+ updateUser: AuthInstance['updateUser'];
723
+ getUser: AuthInstance['getUser'];
724
+ getSession: AuthInstance['getSession'];
725
+ refreshSession: AuthInstance['refreshSession'];
726
+ signOut: AuthInstance['signOut'];
727
+ }
720
728
  /**
721
729
  * 扩展的云实例接口,扩展了云函数调用接口并包含ORM客户端。
722
730
  * @hidden