71 lines
1.6 KiB
JavaScript
71 lines
1.6 KiB
JavaScript
const SESSION_KEY = 'jayucloud-salon_session'
|
|
const LOGIN_PREFERENCE_KEY = 'jayucloud_salon_login_preference'
|
|
const PHONE_BANNER_DISMISSED_KEY = 'jayucloud_salon_phone_banner_dismissed'
|
|
const PROFILE_PROMPT_SKIPPED_KEY = 'jayucloud_salon_profile_prompt_skipped'
|
|
let sessionExpiredHandling = false
|
|
|
|
function getSession() {
|
|
try {
|
|
return wx.getStorageSync(SESSION_KEY) || {}
|
|
} catch (error) {
|
|
return {}
|
|
}
|
|
}
|
|
|
|
function setSession(session, newLoginSession = false) {
|
|
wx.setStorageSync(SESSION_KEY, session || {})
|
|
if (newLoginSession) {
|
|
sessionExpiredHandling = false
|
|
}
|
|
}
|
|
|
|
function clearSession() {
|
|
wx.removeStorageSync(SESSION_KEY)
|
|
}
|
|
|
|
function beginSessionExpiredHandling() {
|
|
if (sessionExpiredHandling) {
|
|
return false
|
|
}
|
|
sessionExpiredHandling = true
|
|
return true
|
|
}
|
|
|
|
function getAccessToken() {
|
|
const session = getSession()
|
|
return session.accessToken || session.token || ''
|
|
}
|
|
|
|
function getLoginPreference() {
|
|
try { return wx.getStorageSync(LOGIN_PREFERENCE_KEY) || {} } catch (error) { return {} }
|
|
}
|
|
|
|
function setLoginPreference(preference) {
|
|
wx.setStorageSync(LOGIN_PREFERENCE_KEY, preference || {})
|
|
}
|
|
|
|
function clearLoginPreference() {
|
|
wx.removeStorageSync(LOGIN_PREFERENCE_KEY)
|
|
}
|
|
|
|
function clearDeviceLoginState() {
|
|
clearSession()
|
|
clearLoginPreference()
|
|
wx.removeStorageSync(PHONE_BANNER_DISMISSED_KEY)
|
|
wx.removeStorageSync(PROFILE_PROMPT_SKIPPED_KEY)
|
|
}
|
|
|
|
module.exports = {
|
|
getSession,
|
|
setSession,
|
|
clearSession,
|
|
beginSessionExpiredHandling,
|
|
getAccessToken,
|
|
getLoginPreference,
|
|
setLoginPreference,
|
|
clearLoginPreference,
|
|
clearDeviceLoginState,
|
|
PHONE_BANNER_DISMISSED_KEY,
|
|
PROFILE_PROMPT_SKIPPED_KEY
|
|
}
|