Skip to content

Commit

Permalink
fix: refresh account info before refresh character info
Browse files Browse the repository at this point in the history
  • Loading branch information
enpitsuLin committed Apr 22, 2024
1 parent 560137b commit 945b9f4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
10 changes: 4 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ async function refreshAccount({ accountMapping, account, token }: { token: strin
const credData = accountMapping[account.id]
if (!credData)
throw new Error(`unexpected error: ID ${account.id} has no its credData`)
const valid = await API.skland.checkAccessToken(credData)
if (!valid) {
const authorizeCode = await API.hypergrayph.grantAuthorizeCode(token)
const { userId, ...credData } = await API.skland.generateCredByCode(authorizeCode)
accountMapping[userId] = credData
}

const authorizeCode = await API.hypergrayph.grantAuthorizeCode(token)
const { userId, ...newCredData } = await API.skland.generateCredByCode(authorizeCode)
accountMapping[userId] = newCredData
const { user, gameStatus } = await API.skland.getUserInfo(credData)
const binding = await API.skland.getPlayerBinding(credData)
account.gameStatus = gameStatus
Expand Down
3 changes: 1 addition & 2 deletions src/utils/proxy-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,8 @@ class AccountService {
const accounts = await accountsStorage.getValue()
const currentAccountId = await currentAccountStorage.getValue()
const account = accounts.find(account => account.id === currentAccountId)

if (account)
await refreshCharacterInfo()
await logInOrRefreshAccount(account.token)
}

async createRefreshInfoAlarm() {
Expand Down

0 comments on commit 945b9f4

Please sign in to comment.