@@ -20,7 +20,7 @@ import { RsRand } from '@/wasm'
20
20
import { Alert } from '@/infra/alert'
21
21
import { LocalState } from '@/ctx/local-state'
22
22
import { ExtConst } from '@/ctx/ext-const'
23
- import { UserService } from '@/service/user-info '
23
+ import { UserService } from '@/service/user.service '
24
24
25
25
async function browserSignIn ( challengeCode : string , scopes : string [ ] ) {
26
26
const para = consUrlPara (
@@ -96,7 +96,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
96
96
const pat = await window . showInputBox ( opt )
97
97
if ( ( pat ?? '' ) . length === 0 ) throw new Error ( '个人访问令牌(PAT)不能为空' )
98
98
99
- return authProvider . onAccessTokenGranted ( pat ?? '' )
99
+ return authProvider . onAccessTokenGranted ( pat ?? '' , true )
100
100
}
101
101
102
102
createSessionFromBrowser ( scopes : string [ ] ) {
@@ -145,7 +145,7 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
145
145
146
146
try {
147
147
const token = await Oauth . getToken ( verifyCode , authCode )
148
- const authSession = await this . onAccessTokenGranted ( token , state =>
148
+ const authSession = await this . onAccessTokenGranted ( token , false , state =>
149
149
progress . report ( { message : state } )
150
150
)
151
151
@@ -182,18 +182,29 @@ export class AuthProvider implements AuthenticationProvider, Disposable {
182
182
this . _sessionChangeEmitter . fire ( { removed : data . remove , added : undefined , changed : undefined } )
183
183
}
184
184
185
- async onAccessTokenGranted ( token : string , onStateChange ?: ( state : string ) => void ) {
185
+ async onAccessTokenGranted ( token : string , isPat : boolean , onStateChange ?: ( state : string ) => void ) {
186
186
onStateChange ?.( '正在获取账户信息...' )
187
187
188
- const userInfo = await UserService . getInfoWithToken ( token )
189
- if ( userInfo === undefined ) throw Error ( '用户信息获取失败' )
190
- const accountInfo = { id : userInfo . space_user_id . toString ( ) , label : userInfo . display_name }
188
+ const userInfo = await UserService . getUserInfoWithToken ( token , isPat )
189
+ if ( userInfo == null ) {
190
+ const errorMsg = '获取用户信息失败: userInfo is null'
191
+ void Alert . warn
192
+ throw Error ( errorMsg )
193
+ }
194
+
195
+ if ( userInfo . blogApp == null )
196
+ void Alert . warn ( '您的账号未开通博客,[立即开通](https://account.cnblogs.com/blog-apply)' )
191
197
192
198
onStateChange ?.( '即将完成...' )
193
199
200
+ const { accountId, displayName } = userInfo
201
+
194
202
const session = < AuthenticationSession > {
195
- account : accountInfo ,
196
- id : `${ this . providerId } -${ userInfo . space_user_id } ` ,
203
+ account : {
204
+ id : new Number ( accountId ) . toString ( ) ,
205
+ label : displayName ,
206
+ } ,
207
+ id : `${ this . providerId } -${ userInfo . accountId } ` ,
197
208
accessToken : token ,
198
209
scopes : this . ensureScopes ( null ) ,
199
210
}
0 commit comments