@cloudbase/auth 3.1.4 → 3.1.5
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 +2 -2
- package/dist/cjs/type.d.ts +10 -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 +2 -2
- package/dist/esm/type.d.ts +10 -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 +4 -3
- package/src/type.ts +11 -0
- package/src/utils.ts +3 -1
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
|
|
|
@@ -1565,7 +1566,7 @@ class Auth {
|
|
|
1565
1566
|
* @param params
|
|
1566
1567
|
* @returns Promise<SignInRes>
|
|
1567
1568
|
*/
|
|
1568
|
-
async verifyOAuth(params?: VerifyOAuthReq): Promise<
|
|
1569
|
+
async verifyOAuth(params?: VerifyOAuthReq): Promise<VerifyOAuthRes> {
|
|
1569
1570
|
const data: any = {}
|
|
1570
1571
|
try {
|
|
1571
1572
|
// 回调至 provider_redirect_uri 地址(url query中携带 授权code,state等参数),此时检查 state 是否符合预期(如 自己设置的 wx_open)
|
|
@@ -1597,7 +1598,7 @@ class Auth {
|
|
|
1597
1598
|
provider_code: code, // 第三方平台跳转回页面时,url param 中携带的 code 参数
|
|
1598
1599
|
})
|
|
1599
1600
|
|
|
1600
|
-
let res:
|
|
1601
|
+
let res: VerifyOAuthRes
|
|
1601
1602
|
|
|
1602
1603
|
if (cacheData.type === OAUTH_TYPE.BIND_IDENTITY) {
|
|
1603
1604
|
res = await this.oauthInstance.authApi.toBindIdentity({ provider_token: token, provider, fireEvent: true })
|
|
@@ -1612,7 +1613,7 @@ class Auth {
|
|
|
1612
1613
|
const localSearch = new URLSearchParams(location?.search)
|
|
1613
1614
|
localSearch.delete('code')
|
|
1614
1615
|
localSearch.delete('state')
|
|
1615
|
-
addUrlSearch(
|
|
1616
|
+
res.data.redirectUrl = addUrlSearch(
|
|
1616
1617
|
cacheData?.search === undefined ? `?${localSearch.toString()}` : cacheData?.search,
|
|
1617
1618
|
cacheData?.hash || location.hash,
|
|
1618
1619
|
)
|
package/src/type.ts
CHANGED
|
@@ -304,3 +304,14 @@ export interface ResetPasswordForOldReq {
|
|
|
304
304
|
old_password: string // 旧密码
|
|
305
305
|
new_password: string // 新密码
|
|
306
306
|
}
|
|
307
|
+
|
|
308
|
+
export interface VerifyOAuthRes {
|
|
309
|
+
data: {
|
|
310
|
+
user?: User // 用户信息
|
|
311
|
+
session?: Session // 会话信息
|
|
312
|
+
redirectUrl?: string // 跳转URL,跳转第三方授权之前的URL或用户调用 signInWithOAuth 时传入的redirectTo
|
|
313
|
+
provider?: string // 绑定的身份源标识
|
|
314
|
+
type?: (typeof OAUTH_TYPE)[keyof typeof OAUTH_TYPE] // 类型(可选),默认为'sign_in', sign_in: 登录,bind_identity: 绑定身份
|
|
315
|
+
}
|
|
316
|
+
error: AuthError | null // 错误信息,成功时为null
|
|
317
|
+
}
|
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
|
/**
|