功能:同步小程序流程
This commit is contained in:
@@ -1,29 +1,57 @@
|
||||
const { STORAGE_KEYS, getStorage, removeStorage, setStorage } = require('./storage')
|
||||
|
||||
/**
|
||||
* Purpose: getAccessToken supports auth.js by holding or executing the get access token page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getAccessToken() {
|
||||
return getStorage(STORAGE_KEYS.ACCESS_TOKEN, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getRefreshToken supports auth.js by holding or executing the get refresh token page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getRefreshToken() {
|
||||
return getStorage(STORAGE_KEYS.REFRESH_TOKEN, '')
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getStoredUserInfo supports auth.js by holding or executing the get stored user info page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getStoredUserInfo() {
|
||||
return getStorage(STORAGE_KEYS.USER_INFO, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getStoredPermissions supports auth.js by holding or executing the get stored permissions page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getStoredPermissions() {
|
||||
return getStorage(STORAGE_KEYS.PERMISSIONS, [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: getCurrentShop supports auth.js by holding or executing the get current shop page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function getCurrentShop() {
|
||||
return getStorage(STORAGE_KEYS.CURRENT_SHOP, null)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: isLoggedIn supports auth.js by holding or executing the is logged in page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function isLoggedIn() {
|
||||
return Boolean(getAccessToken())
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setSession supports auth.js by holding or executing the set session page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function setSession(payload) {
|
||||
if (!payload || !payload.accessToken || !payload.refreshToken) {
|
||||
return
|
||||
@@ -46,6 +74,10 @@ function setSession(payload) {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: updateStoredUserInfo supports auth.js by holding or executing the update stored user info page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function updateStoredUserInfo(userInfo) {
|
||||
if (!userInfo) {
|
||||
removeStorage(STORAGE_KEYS.USER_INFO)
|
||||
@@ -55,14 +87,26 @@ function updateStoredUserInfo(userInfo) {
|
||||
setStorage(STORAGE_KEYS.USER_INFO, userInfo)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setPermissions supports auth.js by holding or executing the set permissions page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function setPermissions(permissions) {
|
||||
setStorage(STORAGE_KEYS.PERMISSIONS, Array.isArray(permissions) ? permissions : [])
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearPermissions supports auth.js by holding or executing the clear permissions page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function clearPermissions() {
|
||||
removeStorage(STORAGE_KEYS.PERMISSIONS)
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: setCurrentShop supports auth.js by holding or executing the set current shop page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function setCurrentShop(shop) {
|
||||
if (!shop || !shop.id) {
|
||||
removeStorage(STORAGE_KEYS.CURRENT_SHOP)
|
||||
@@ -75,6 +119,10 @@ function setCurrentShop(shop) {
|
||||
})
|
||||
}
|
||||
|
||||
/**
|
||||
* Purpose: clearSession supports auth.js by holding or executing the clear session page or API role.
|
||||
* Usage: import, call, read, or update this function from the owning page/module while preserving the surrounding loading and permission flow.
|
||||
*/
|
||||
function clearSession() {
|
||||
removeStorage(STORAGE_KEYS.ACCESS_TOKEN)
|
||||
removeStorage(STORAGE_KEYS.REFRESH_TOKEN)
|
||||
|
||||
Reference in New Issue
Block a user