fix: 修复token失效时更新token的bug

This commit is contained in:
范鹏 2025-03-24 15:26:37 +08:00
parent 9ddbc35238
commit aea953d60b
3 changed files with 10 additions and 9 deletions

View File

@ -250,9 +250,10 @@ export async function cleanLockUser() {
/** /**
* 登录星云 * 登录星云
* @param {Number} [uid] 用户ID * @param {Number} [uid] 用户ID
* @param {Boolean} [force] 是否强制更新
* @returns Result * @returns Result
*/ */
export async function login(uid) { export async function login(uid, force = false) {
let accounts = getStorage('starCloudAccount') let accounts = getStorage('starCloudAccount')
let userInfos = getStorage('starCloudUser') let userInfos = getStorage('starCloudUser')
if (!accounts) { if (!accounts) {
@ -266,7 +267,7 @@ export async function login(uid) {
this.accountInfo = accounts[id] this.accountInfo = accounts[id]
if (this.accountInfo) { if (this.accountInfo) {
if (this.accountInfo.token) { if (this.accountInfo.token && !force) {
this.userInfo = userInfos[id] this.userInfo = userInfos[id]
setStorage('starCloudToken', this.accountInfo.token) setStorage('starCloudToken', this.accountInfo.token)

View File

@ -24,7 +24,7 @@ const request = config => {
// 默认请求头 // 默认请求头
const headerDefault = { const headerDefault = {
version: baseConfig.version + '+' + baseConfig.buildNumber version: baseConfig.version
} }
const header = { const header = {
...headerDefault, ...headerDefault,
@ -61,9 +61,9 @@ const request = config => {
removeStorage('starCloudToken') removeStorage('starCloudToken')
removeStorage('starCloudUser') removeStorage('starCloudUser')
const { code } = await starCloud.login({ const { code } = await starCloud.login({
username: starCloud.starCloudAccountInfo.username, username: starCloud.accountInfo.username,
password: starCloud.starCloudAccountInfo.password, password: starCloud.accountInfo.password,
uid: starCloud.starCloudAccountInfo.uid uid: starCloud.accountInfo.uid
}) })
if (code === Result.Success.code) { if (code === Result.Success.code) {
resolve(await request(config)) resolve(await request(config))

View File

@ -81,9 +81,9 @@ const request = (config) => {
removeStorage('starCloudToken') removeStorage('starCloudToken')
removeStorage('starCloudUser') removeStorage('starCloudUser')
const loginResult = await starCloud.login({ const loginResult = await starCloud.login({
username: starCloud.starCloudAccountInfo.username, username: starCloud.accountInfo.username,
password: starCloud.starCloudAccountInfo.password, password: starCloud.accountInfo.password,
uid: starCloud.starCloudAccountInfo.uid uid: starCloud.accountInfo.uid
}) })
if (loginResult.code === Result.Success.code) { if (loginResult.code === Result.Success.code) {
return resolve(await request(config)) return resolve(await request(config))