fix loading issue and api error on empty response
This commit is contained in:
@@ -46,6 +46,7 @@ export default function LoginPage() {
|
||||
if (result.success) {
|
||||
// Redirect to verify page with mobile number
|
||||
router.push(`/verify-code?mobile=${encodeURIComponent(normalizedMobile)}`)
|
||||
return // Don't set loading to false — component will unmount
|
||||
} else {
|
||||
setError(result.message || 'خطا در ارسال کد')
|
||||
}
|
||||
|
||||
@@ -62,6 +62,7 @@ export default function Home() {
|
||||
if (result.success) {
|
||||
// Redirect to verify page with mobile number
|
||||
router.push(`/verify-code?mobile=${encodeURIComponent(normalizedMobile)}`)
|
||||
return // Don't set loading to false — component will unmount
|
||||
} else {
|
||||
setError(result.message || 'خطا در ارسال کد')
|
||||
}
|
||||
|
||||
@@ -93,14 +93,17 @@ function VerifyCodeContent() {
|
||||
} else if (devicesResult.totalCount === 1) {
|
||||
// Single device - redirect to calendar
|
||||
router.push(`/calendar?deviceId=${devicesResult.items[0].id}`)
|
||||
return // Don't set loading to false — component will unmount
|
||||
} else {
|
||||
// Multiple devices - redirect to device list
|
||||
router.push('/devices')
|
||||
return // Don't set loading to false — component will unmount
|
||||
}
|
||||
} catch (deviceError) {
|
||||
console.error('Error fetching devices:', deviceError)
|
||||
// Still redirect to devices page to handle error there
|
||||
router.push('/devices')
|
||||
return // Don't set loading to false — component will unmount
|
||||
}
|
||||
} else {
|
||||
setError(result.message || 'کد وارد شده نادرست است')
|
||||
|
||||
Reference in New Issue
Block a user