From ec58d6a00277bb0b4de972e736901f31ace54c9c Mon Sep 17 00:00:00 2001 From: wangyaqi Date: Fri, 10 Feb 2023 20:57:56 +0800 Subject: [PATCH] fix: refresh token error --- .../cloudfunctions/uni-id-co/lang/zh-hans.js | 2 ++ .../cloudfunctions/uni-id-co/lib/utils/login.js | 12 +++++++++--- .../uni-id-co/lib/utils/register.js | 15 +++++++++++---- .../uni-id-co/module/utils/refresh-token.js | 11 ++++++++--- 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js index bfffac7..96a0a70 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lang/zh-hans.js @@ -4,6 +4,8 @@ const word = { } const sentence = { + 'uni-id-token-expired': '登录状态失效,token已过期', + 'uni-id-check-token-failed': 'token校验未通过', 'uni-id-account-exists': '此账号已注册', 'uni-id-account-not-exists': '此账号未注册', 'uni-id-account-not-exists-in-current-app': '此账号未在该应用注册', diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js index 6f863bc..00beec9 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/login.js @@ -194,12 +194,18 @@ async function postLogin (params = {}) { last_login_ip: clientIP, ...extraData } + const createTokenRes = await this.uniIdCommon.createToken({ + uid + }) + const { + errCode, token, tokenExpired - } = await this.uniIdCommon.createToken({ - uid - }) + } = createTokenRes + if (errCode) { + throw createTokenRes + } if (uniIdToken) { try { diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js index 24eec34..a500b84 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/lib/utils/register.js @@ -157,7 +157,7 @@ async function postRegister (params = {}) { if (uniIdToken) { try { await logout.call(this) - } catch (error) {} + } catch (error) { } } const beforeRegister = this.hooks.beforeRegister @@ -173,12 +173,19 @@ async function postRegister (params = {}) { id: uid } = await userCollection.add(userRecord) + const createTokenRes = await this.uniIdCommon.createToken({ + uid + }) + const { + errCode, token, tokenExpired - } = await this.uniIdCommon.createToken({ - uid - }) + } = createTokenRes + + if (errCode) { + throw createTokenRes + } await this.middleware.uniIdLog({ data: { diff --git a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/refresh-token.js b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/refresh-token.js index 4b0d0a8..b12f1f0 100644 --- a/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/refresh-token.js +++ b/uni_modules/uni-id-pages/uniCloud/cloudfunctions/uni-id-co/module/utils/refresh-token.js @@ -3,12 +3,17 @@ * @tutorial https://uniapp.dcloud.net.cn/uniCloud/uni-id-pages.html#refresh-token */ module.exports = async function () { + const refreshTokenRes = await this.uniIdCommon.refreshToken({ + token: this.getUniversalUniIdToken() + }) const { + errCode, token, tokenExpired - } = await this.uniIdCommon.refreshToken({ - token: this.getUniversalUniIdToken() - }) + } = refreshTokenRes + if (errCode) { + throw refreshTokenRes + } return { errCode: 0, newToken: { -- GitLab