fix
This commit is contained in:
parent
04fb72c14c
commit
a2986c631b
|
|
@ -30,26 +30,26 @@ export interface UserProfile {
|
|||
isActive: boolean;
|
||||
}
|
||||
|
||||
export interface AuthResponse {
|
||||
export interface AuthResponse<T> {
|
||||
success: boolean;
|
||||
message: string;
|
||||
data?: any;
|
||||
data?: AuthResponseData<T>;
|
||||
output?: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
export interface PythonCliAuthResponse {
|
||||
export interface AuthResponseData<T> {
|
||||
success: boolean;
|
||||
message: string;
|
||||
data?: {
|
||||
user?: UserProfile;
|
||||
token?: string;
|
||||
expires_at?: string;
|
||||
};
|
||||
output?: string;
|
||||
error?: string;
|
||||
data: T;
|
||||
}
|
||||
|
||||
export type PythonCliAuthResponse = AuthResponse<{
|
||||
user?: UserProfile;
|
||||
token?: string;
|
||||
expires_at?: string;
|
||||
}>;
|
||||
|
||||
class PythonCliAuth {
|
||||
private token: string | null = null;
|
||||
private user: UserProfile | null = null;
|
||||
|
|
@ -139,40 +139,31 @@ class PythonCliAuth {
|
|||
display_name: credentials.displayName,
|
||||
}
|
||||
});
|
||||
console.log({ response })
|
||||
if (!response.success) {
|
||||
throw new Error(response.error || response.message || 'Registration failed');
|
||||
}
|
||||
|
||||
const data = response.data;
|
||||
// 解析输出中的用户信息和token
|
||||
if (response.success && response.output) {
|
||||
// 尝试从输出中解析JSON
|
||||
const jsonMatch = response.output.match(/\{[\s\S]*\}/);
|
||||
if (jsonMatch) {
|
||||
try {
|
||||
const authData = JSON.parse(jsonMatch[0]);
|
||||
if (authData.success && authData.data?.user && authData.data?.token) {
|
||||
this.token = authData.data.token;
|
||||
this.user = {
|
||||
id: authData.data.user.id,
|
||||
username: authData.data.user.username,
|
||||
displayName: authData.data.user.display_name,
|
||||
email: authData.data.user.email,
|
||||
avatarUrl: authData.data.user.avatar_url,
|
||||
createTime: authData.data.user.created_at,
|
||||
updateTime: authData.data.user.updated_at,
|
||||
lastLogin: authData.data.user.last_login,
|
||||
isActive: authData.data.user.is_active
|
||||
};
|
||||
if (data && data.success) {
|
||||
const authData = data;
|
||||
if (authData.success && authData.data?.user && authData.data?.token) {
|
||||
this.token = authData.data.token;
|
||||
this.user = {
|
||||
id: authData.data.user.id,
|
||||
username: authData.data.user.username,
|
||||
displayName: authData.data.user.displayName,
|
||||
email: authData.data.user.email,
|
||||
avatarUrl: authData.data.user.avatarUrl,
|
||||
createTime: authData.data.user.createTime,
|
||||
updateTime: authData.data.user.updateTime,
|
||||
lastLogin: authData.data.user.lastLogin,
|
||||
isActive: authData.data.user.isActive
|
||||
};
|
||||
|
||||
// 保存到localStorage
|
||||
this.saveAuthToStorage();
|
||||
// 保存到localStorage
|
||||
this.saveAuthToStorage();
|
||||
|
||||
return this.user;
|
||||
}
|
||||
} catch (parseError) {
|
||||
console.error('Failed to parse auth response JSON:', parseError);
|
||||
}
|
||||
return this.user;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue