@@ -21,8 +21,8 @@ function CallbackContent() {
2121 if ( state ) {
2222 try {
2323 return decodeURIComponent ( state ) ;
24- } catch ( e ) {
25- console . warn ( '解析state参数失败:' , e ) ;
24+ } catch {
25+ // 解析失败时忽略state参数
2626 }
2727 }
2828
@@ -53,7 +53,6 @@ function CallbackContent() {
5353 saveAuthData ( authData ) ;
5454 setStatus ( '登录成功! 正在跳转...' ) ;
5555 setState ( 'success' ) ;
56- console . log ( '认证数据:' , authData ) ;
5756
5857 // 跳转到原来的页面
5958 const redirectUrl = getRedirectUrl ( ) ;
@@ -97,14 +96,27 @@ function CallbackContent() {
9796 const code = searchParams . get ( 'code' ) ;
9897
9998 if ( ! code ) {
100- setStatus ( '未收到授权码或Token' ) ;
99+ setStatus ( '未收到授权码或Token,请重新尝试登录 ' ) ;
101100 setState ( 'error' ) ;
102101
103102 return ;
104103 }
105104
105+ setStatus ( '正在与GitHub服务器通信...' ) ;
106+
106107 const { data, error } = await authApi . githubCallback ( code , {
107- onError : ( error ) => console . error ( 'GitHub认证出错:' , error ) ,
108+ onError : ( error ) => {
109+ // 处理不同类型的错误
110+ if ( error instanceof Error ) {
111+ if ( error . message . includes ( '超时' ) || error . message . includes ( 'timeout' ) ) {
112+ setStatus ( 'GitHub认证超时,请重试或检查网络连接' ) ;
113+ } else if ( error . message . includes ( '网络' ) ) {
114+ setStatus ( '网络连接错误,请检查您的网络设置' ) ;
115+ } else {
116+ setStatus ( `认证失败: ${ error . message } ` ) ;
117+ }
118+ }
119+ } ,
108120 } ) ;
109121
110122 if ( error ) {
@@ -122,9 +134,19 @@ function CallbackContent() {
122134 setState ( 'error' ) ;
123135 }
124136 } catch ( e ) {
125- setStatus ( '登录过程中发生错误' ) ;
137+ if ( e instanceof Error ) {
138+ if ( e . message . includes ( 'Failed to fetch' ) || e . message . includes ( 'Network' ) ) {
139+ setStatus ( '网络连接失败,请检查网络设置后重试' ) ;
140+ } else if ( e . message . includes ( 'timeout' ) || e . message . includes ( '超时' ) ) {
141+ setStatus ( '请求超时,服务器响应较慢,请重试' ) ;
142+ } else {
143+ setStatus ( `认证失败: ${ e . message } ` ) ;
144+ }
145+ } else {
146+ setStatus ( '登录过程中发生未知错误,请重试' ) ;
147+ }
148+
126149 setState ( 'error' ) ;
127- console . error ( e ) ;
128150 }
129151 } ;
130152
@@ -155,13 +177,26 @@ function CallbackContent() {
155177 { state === 'error' && (
156178 < div className = "flex flex-col items-center" >
157179 < AlertCircle className = "h-14 w-14 text-red-500 mb-4" />
158- < p className = "text-lg font-medium text-gray-700" > { status } </ p >
159- < button
160- className = "mt-6 py-2 px-4 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors"
161- onClick = { ( ) => router . push ( '/auth' ) }
162- >
163- 返回登录
164- </ button >
180+ < p className = "text-lg font-medium text-gray-700 text-center mb-4" > { status } </ p >
181+ < div className = "flex space-x-3" >
182+ < button
183+ className = "py-2 px-4 bg-blue-500 hover:bg-blue-600 text-white rounded-lg transition-colors"
184+ onClick = { ( ) => {
185+ setState ( 'loading' ) ;
186+ setStatus ( '重新尝试认证...' ) ;
187+ // 重新触发认证流程
188+ window . location . reload ( ) ;
189+ } }
190+ >
191+ 重试
192+ </ button >
193+ < button
194+ className = "py-2 px-4 bg-gray-500 hover:bg-gray-600 text-white rounded-lg transition-colors"
195+ onClick = { ( ) => router . push ( '/auth' ) }
196+ >
197+ 返回登录
198+ </ button >
199+ </ div >
165200 </ div >
166201 ) }
167202 </ div >
0 commit comments