Skip to content

Commit

Permalink
fix: user login status update
Browse files Browse the repository at this point in the history
  • Loading branch information
ci010 committed Jan 8, 2022
1 parent 6adc271 commit 6a13d3c
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions xmcl-runtime/lib/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,14 @@ export default class UserService extends StatefulService<UserState> implements I
], async () => {
await this.userFile.write(this.state)
})
this.storeManager.subscribeAll(['userProfileUpdate', 'userGameProfileSelect', 'userInvalidate'], async () => {
const user = this.state.user
if (!this.state.isAccessTokenValid) {
this.diagnoseService.report({ userNotLogined: [{ authService: user.authService, account: user.username }] })
} else {
this.diagnoseService.report({ userNotLogined: [] })
}
})
}

async initialize() {
Expand Down Expand Up @@ -194,7 +202,7 @@ export default class UserService extends StatefulService<UserState> implements I
async submitChallenges(responses: MojangChallengeResponse[]) {
if (!this.state.isAccessTokenValid) throw new Error('Cannot submit challenge if not logined')
const user = this.state.user
if (user.authService !== 'mojang') throw new Error('Cannot sumit challenge if login mode is not mojang!')
if (user.authService !== 'mojang') throw new Error('Cannot submit challenge if login mode is not mojang!')
if (!(responses instanceof Array)) throw new Error('Expect responses Array!')
const result = await responseChallenges(user.accessToken, responses)
this.state.userSecurity(true)
Expand Down Expand Up @@ -246,10 +254,6 @@ export default class UserService extends StatefulService<UserState> implements I
} else {
this.log(`Current user ${user.id} is not YggdrasilService. Skip to refresh credential.`)
}

if (!this.state.isAccessTokenValid) {
this.diagnoseService.report({ userNotLogined: [{ authService: user.authService, account: user.username }] })
}
}

/**
Expand Down Expand Up @@ -388,7 +392,6 @@ export default class UserService extends StatefulService<UserState> implements I
@Singleton()
async refreshUser() {
if (!this.state.isAccessTokenValid) {
this.diagnoseService.report({ userNotLogined: [{ authService: this.state.user.authService, account: this.state.user.username }] })
return
}
await this.refreshStatus().catch(_ => _)
Expand Down

0 comments on commit 6a13d3c

Please sign in to comment.