csv
All checks were successful
Deploy to Server / deploy (push) Successful in 24s

This commit is contained in:
jeremygan2021
2026-02-28 11:28:35 +08:00
parent 4f4cfcd6f4
commit dba9d4f724
4 changed files with 177 additions and 13 deletions

View File

@@ -26,12 +26,23 @@ function App({ children }: PropsWithChildren<any>) {
}
}
// Auto login
login().then(res => {
console.log('Logged in as:', res?.nickname)
}).catch(err => {
console.log('Auto login failed', err)
})
// Auto login only if user info with phone number exists
const userInfo = Taro.getStorageSync('userInfo')
if (userInfo && userInfo.phone_number) {
console.log('User has phone number, attempting auto login...')
login().then(res => {
console.log('Auto login success, user:', res?.nickname)
}).catch(err => {
console.log('Auto login failed', err)
// If login fails (e.g. user deleted on backend), clear storage
if (err.statusCode === 404 || err.statusCode === 401) {
Taro.removeStorageSync('userInfo')
Taro.removeStorageSync('token')
}
})
} else {
console.log('No phone number found, skipping auto login')
}
})
return children