@cloudbase/auth 3.1.4 → 3.1.6
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/dist/cjs/index.d.ts +2 -2
- package/dist/cjs/index.js +19 -10
- package/dist/cjs/type.d.ts +13 -0
- package/dist/cjs/type.js +1 -1
- package/dist/cjs/utils.d.ts +1 -1
- package/dist/cjs/utils.js +2 -1
- package/dist/esm/index.d.ts +2 -2
- package/dist/esm/index.js +19 -10
- package/dist/esm/type.d.ts +13 -0
- package/dist/esm/type.js +1 -1
- package/dist/esm/utils.d.ts +1 -1
- package/dist/esm/utils.js +2 -1
- package/dist/miniprogram/index.js +1 -1
- package/package.json +5 -5
- package/src/index.ts +11 -3
- package/src/type.ts +14 -0
- package/src/utils.ts +3 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudbase/auth",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.6",
|
|
4
4
|
"description": "cloudbase javascript sdk auth componets",
|
|
5
5
|
"main": "dist/cjs/index.js",
|
|
6
6
|
"module": "dist/esm/index.js",
|
|
@@ -32,14 +32,14 @@
|
|
|
32
32
|
"license": "Apache-2.0",
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@cloudbase/adapter-wx_mp": "^1.3.1",
|
|
35
|
-
"@cloudbase/oauth": "3.1.
|
|
36
|
-
"@cloudbase/utilities": "3.1.
|
|
35
|
+
"@cloudbase/oauth": "3.1.6",
|
|
36
|
+
"@cloudbase/utilities": "3.1.6"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@cloudbase/types": "3.1.
|
|
39
|
+
"@cloudbase/types": "3.1.6",
|
|
40
40
|
"@types/node": "^22.1.0",
|
|
41
41
|
"terser-webpack-plugin": "^3.0.2",
|
|
42
42
|
"webpack-bundle-analyzer": "^4.9.1"
|
|
43
43
|
},
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "abd1ab7bf498cfc3042606fb92f436b1c5f8b2c3"
|
|
45
45
|
}
|
package/src/index.ts
CHANGED
|
@@ -59,6 +59,7 @@ import {
|
|
|
59
59
|
UpdateUserReq,
|
|
60
60
|
UpdateUserWithVerificationRes,
|
|
61
61
|
VerifyOAuthReq,
|
|
62
|
+
VerifyOAuthRes,
|
|
62
63
|
VerifyOtpReq,
|
|
63
64
|
} from './type'
|
|
64
65
|
|
|
@@ -1534,6 +1535,13 @@ class Auth {
|
|
|
1534
1535
|
* @returns Promise<SignInWithOtpRes>
|
|
1535
1536
|
*/
|
|
1536
1537
|
async signInWithOtp(params: SignInWithOtpReq): Promise<SignInWithOtpRes> {
|
|
1538
|
+
if (params.options?.shouldCreateUser === undefined || !!params.options?.shouldCreateUser) {
|
|
1539
|
+
return this.signUp({
|
|
1540
|
+
email: params.email,
|
|
1541
|
+
phone: params.phone,
|
|
1542
|
+
})
|
|
1543
|
+
}
|
|
1544
|
+
|
|
1537
1545
|
try {
|
|
1538
1546
|
// 参数校验:email或phone必填其一
|
|
1539
1547
|
this.validateAtLeastOne(params, [['email'], ['phone']], 'You must provide either an email or phone number')
|
|
@@ -1565,7 +1573,7 @@ class Auth {
|
|
|
1565
1573
|
* @param params
|
|
1566
1574
|
* @returns Promise<SignInRes>
|
|
1567
1575
|
*/
|
|
1568
|
-
async verifyOAuth(params?: VerifyOAuthReq): Promise<
|
|
1576
|
+
async verifyOAuth(params?: VerifyOAuthReq): Promise<VerifyOAuthRes> {
|
|
1569
1577
|
const data: any = {}
|
|
1570
1578
|
try {
|
|
1571
1579
|
// 回调至 provider_redirect_uri 地址(url query中携带 授权code,state等参数),此时检查 state 是否符合预期(如 自己设置的 wx_open)
|
|
@@ -1597,7 +1605,7 @@ class Auth {
|
|
|
1597
1605
|
provider_code: code, // 第三方平台跳转回页面时,url param 中携带的 code 参数
|
|
1598
1606
|
})
|
|
1599
1607
|
|
|
1600
|
-
let res:
|
|
1608
|
+
let res: VerifyOAuthRes
|
|
1601
1609
|
|
|
1602
1610
|
if (cacheData.type === OAUTH_TYPE.BIND_IDENTITY) {
|
|
1603
1611
|
res = await this.oauthInstance.authApi.toBindIdentity({ provider_token: token, provider, fireEvent: true })
|
|
@@ -1612,7 +1620,7 @@ class Auth {
|
|
|
1612
1620
|
const localSearch = new URLSearchParams(location?.search)
|
|
1613
1621
|
localSearch.delete('code')
|
|
1614
1622
|
localSearch.delete('state')
|
|
1615
|
-
addUrlSearch(
|
|
1623
|
+
res.data.redirectUrl = addUrlSearch(
|
|
1616
1624
|
cacheData?.search === undefined ? `?${localSearch.toString()}` : cacheData?.search,
|
|
1617
1625
|
cacheData?.hash || location.hash,
|
|
1618
1626
|
)
|
package/src/type.ts
CHANGED
|
@@ -227,6 +227,9 @@ export interface VerifyOtpReq {
|
|
|
227
227
|
export interface SignInWithOtpReq {
|
|
228
228
|
email?: string // 邮箱(可选,与手机号二选一)
|
|
229
229
|
phone?: string // 手机号(可选,与邮箱二选一)
|
|
230
|
+
options?: {
|
|
231
|
+
shouldCreateUser?: boolean // 如果用户不存在是否创建用户,默认为true
|
|
232
|
+
}
|
|
230
233
|
}
|
|
231
234
|
|
|
232
235
|
/**
|
|
@@ -304,3 +307,14 @@ export interface ResetPasswordForOldReq {
|
|
|
304
307
|
old_password: string // 旧密码
|
|
305
308
|
new_password: string // 新密码
|
|
306
309
|
}
|
|
310
|
+
|
|
311
|
+
export interface VerifyOAuthRes {
|
|
312
|
+
data: {
|
|
313
|
+
user?: User // 用户信息
|
|
314
|
+
session?: Session // 会话信息
|
|
315
|
+
redirectUrl?: string // 跳转URL,跳转第三方授权之前的URL或用户调用 signInWithOAuth 时传入的redirectTo
|
|
316
|
+
provider?: string // 绑定的身份源标识
|
|
317
|
+
type?: (typeof OAUTH_TYPE)[keyof typeof OAUTH_TYPE] // 类型(可选),默认为'sign_in', sign_in: 登录,bind_identity: 绑定身份
|
|
318
|
+
}
|
|
319
|
+
error: AuthError | null // 错误信息,成功时为null
|
|
320
|
+
}
|
package/src/utils.ts
CHANGED
|
@@ -31,7 +31,7 @@ export function removeBrowserSession(key: string) {
|
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
|
-
export function addUrlSearch(search: Location['search'], hash?: Location['hash']) {
|
|
34
|
+
export function addUrlSearch(search: Location['search'], hash?: Location['hash']): string {
|
|
35
35
|
if (search === undefined) return
|
|
36
36
|
|
|
37
37
|
// 1. 解析当前 URL
|
|
@@ -44,6 +44,8 @@ export function addUrlSearch(search: Location['search'], hash?: Location['hash']
|
|
|
44
44
|
|
|
45
45
|
// 3. 更新地址栏(保留哈希值)
|
|
46
46
|
window.history.replaceState({}, '', url.href)
|
|
47
|
+
|
|
48
|
+
return url.href
|
|
47
49
|
}
|
|
48
50
|
|
|
49
51
|
/**
|