fix
This commit is contained in:
parent
b819337600
commit
ae8664db48
|
|
@ -31,6 +31,7 @@ export interface UserProfile {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthResponse<T> {
|
export interface AuthResponse<T> {
|
||||||
|
// 代表命令行是否执行成功
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
data?: AuthResponseData<T>;
|
data?: AuthResponseData<T>;
|
||||||
|
|
@ -39,6 +40,7 @@ export interface AuthResponse<T> {
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AuthResponseData<T> {
|
export interface AuthResponseData<T> {
|
||||||
|
// 代表结果是否成功
|
||||||
success: boolean;
|
success: boolean;
|
||||||
message: string;
|
message: string;
|
||||||
data: T;
|
data: T;
|
||||||
|
|
@ -81,45 +83,38 @@ class PythonCliAuth {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
console.log({ response })
|
// 第一层:检查命令行是否执行成功
|
||||||
|
|
||||||
if (!response.success) {
|
if (!response.success) {
|
||||||
throw new Error(response.error || response.message || 'Login failed');
|
throw new Error(response.error || response.message || 'Command execution failed');
|
||||||
}
|
}
|
||||||
|
|
||||||
// 解析输出中的用户信息和token
|
const data = response.data;
|
||||||
if (response.success && response.output) {
|
// 第二层:检查认证逻辑是否成功
|
||||||
// 尝试从输出中解析JSON
|
if (data && data.success) {
|
||||||
const jsonMatch = response.output.match(/\{[\s\S]*\}/);
|
const authData = data;
|
||||||
if (jsonMatch) {
|
if (authData.success && authData.data?.user && authData.data?.token) {
|
||||||
try {
|
this.token = authData.data.token;
|
||||||
const authData = JSON.parse(jsonMatch[0]);
|
this.user = {
|
||||||
if (authData.success && authData.data?.user && authData.data?.token) {
|
id: authData.data.user.id,
|
||||||
this.token = authData.data.token;
|
username: authData.data.user.username,
|
||||||
this.user = {
|
displayName: authData.data.user.displayName,
|
||||||
id: authData.data.user.id,
|
email: authData.data.user.email,
|
||||||
username: authData.data.user.username,
|
avatarUrl: authData.data.user.avatarUrl,
|
||||||
displayName: authData.data.user.display_name,
|
createTime: authData.data.user.createTime,
|
||||||
email: authData.data.user.email,
|
updateTime: authData.data.user.updateTime,
|
||||||
avatarUrl: authData.data.user.avatar_url,
|
lastLogin: authData.data.user.lastLogin,
|
||||||
createTime: authData.data.user.created_at,
|
isActive: authData.data.user.isActive
|
||||||
updateTime: authData.data.user.updated_at,
|
};
|
||||||
lastLogin: authData.data.user.last_login,
|
|
||||||
isActive: authData.data.user.is_active
|
|
||||||
};
|
|
||||||
|
|
||||||
// 保存到localStorage
|
// 保存到localStorage
|
||||||
this.saveAuthToStorage();
|
this.saveAuthToStorage();
|
||||||
|
|
||||||
return this.user;
|
return this.user;
|
||||||
}
|
|
||||||
} catch (parseError) {
|
|
||||||
console.error('Failed to parse auth response JSON:', parseError);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
throw new Error(response.error || response.message || 'Login failed');
|
// 认证逻辑失败
|
||||||
|
throw new Error(data?.message || 'Authentication failed');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Login failed:', error);
|
console.error('Login failed:', error);
|
||||||
throw error;
|
throw error;
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue