Taro.checkSession(option)
Checks if the login status has expired.
A user login status obtained via the Taro.login
API is time-sensitive. The Mini Program is more likely to expire when it is not used for a longer time. On the contrary, if the user keeps using the Mini Program, the user login status keeps effective. The specific time logic is maintained by WeChat and transparent to developers. Developers need only to call the Taro.checkSession
API to check whether the current user login status has expired.
After a login status expired, developers can call the wx.login again to get the latest user login status. If the API is called successfully, the current session_key remains effective; if the call to the API failed, the session_key has expired. For more usages, see Mini Program Login.
Type
(option?: Option) => Promise<CallbackResult>
Parameters
Option
Property | Type | Required | Description |
---|---|---|---|
complete | (res: any) => void | No | The callback function used when the API call completed (always executed whether the call succeeds or fails) |
fail | (res: any) => void | No | The callback function for a failed API call |
success | (res: Result) => void | No | The callback function for a successful API call |
Sample Code
Taro.checkSession({
success: function () {
//session_key has not expired and will remain effective for the current lifecycle.
},
fail: function () {
// session_key has expired and the user needs to log in again.
Taro.login() // Re-login
}
})
API Support
API | WeChat Mini-Program | H5 | React Native |
---|---|---|---|
Taro.checkSession | ✔️ |