Skip to content

Commit

Permalink
feat:saveLoginState 改为开放,新增bindWxByCode
Browse files Browse the repository at this point in the history
  • Loading branch information
周雅风 committed Nov 14, 2023
1 parent 3b1d167 commit be3433a
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 5 deletions.
50 changes: 46 additions & 4 deletions packages/miniapp/src/Authing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import {
UpdateEmailRequestOptions,
UpdatePhoneRequestOptions,
DeleteAccountRequestOptions,
GerUserInfo
GerUserInfo,
BindWxByCodeOptions

Check failure on line 36 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 1 tab but found 2 spaces
} from './types'

import { returnSuccess, returnError } from './helpers/return'
Expand Down Expand Up @@ -93,8 +94,12 @@ export class Authing {
})
}
}

private async saveLoginState(
/**

Check failure on line 97 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 1 tab but found 0
*
* @param loginState 登录用户状态信息
* @returns
*/
async saveLoginState(
loginState: LoginState
): Promise<LoginState> {
const _loginState: LoginState = {
Expand Down Expand Up @@ -616,7 +621,44 @@ export class Authing {
}

return returnSuccess(updateProfileRes)
}
}

Check failure on line 624 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 1 tab but found 2 spaces

async bindWxByCode(data:BindWxByCodeOptions) {

Check failure on line 626 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 1 tab but found 2 spaces
const [error, loginState] = await this.getLoginState()

Check failure on line 627 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 2 tabs but found 4 spaces

if (error) {
return returnError({
message: 'Token has expired, please login again'
})
}

const { access_token, expires_at } = loginState as LoginState

if (expires_at < Date.now()) {
return returnError({
message: 'Token has expired, please login again'
})
}

Check failure on line 641 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 2 tabs but found 4 spaces

const [err, res] = await request({

Check failure on line 643 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 2 tabs but found 4 spaces
method: 'POST',
url: `${this.options.host}/connections/social/wechat-miniprogram/bind`,
data,
header: {
'x-authing-userpool-id': this.options.userPoolId,
Authorization: access_token
}
})

if (err) {
return returnError(err)
}

return returnSuccess(res)

}

Check failure on line 659 in packages/miniapp/src/Authing.ts

View workflow job for this annotation

GitHub Actions / readyGo

Expected indentation of 1 tab but found 2 spaces



// 绑定邮箱
async bindEmail(data: BindEmailOptions) {
Expand Down
12 changes: 11 additions & 1 deletion packages/miniapp/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -481,4 +481,14 @@ export interface GerUserInfo {
withDepartmentIds?: boolean
withCustomData?: boolean
withIdentities?: boolean
}
}

export interface BindWxByCodeOptions{
code: string,
options?: {
iv?: string;
encryptedData?: string;
// wx.getUserInfo 返回的 rawData, 里面包含了原始用户数据
rawData?: string;
}
}

0 comments on commit be3433a

Please sign in to comment.