|
@@ -2,14 +2,30 @@ import Cookies from 'js-cookie'
|
|
|
|
|
|
const TokenKey = 'Admin-Token'
|
|
|
|
|
|
+function getCookieDomain() {
|
|
|
+ let host = location.hostname
|
|
|
+ const ip = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/
|
|
|
+ if (ip.test(host) === true || host === 'localhost') return host
|
|
|
+ const regex = /([^]*).*/
|
|
|
+ const match = host.match(regex)
|
|
|
+ if (typeof match !== 'undefined' && match !== null) host = match[1]
|
|
|
+ if (typeof host !== 'undefined' && host !== null) {
|
|
|
+ const strAry = host.split('.')
|
|
|
+ if (strAry.length > 1) {
|
|
|
+ host = strAry[strAry.length - 2] + '.' + strAry[strAry.length - 1]
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return '.' + host
|
|
|
+}
|
|
|
+
|
|
|
export function getToken() {
|
|
|
- return Cookies.get(TokenKey)
|
|
|
+ return Cookies.get(TokenKey, { domain: getCookieDomain() })
|
|
|
}
|
|
|
|
|
|
export function setToken(token) {
|
|
|
- return Cookies.set(TokenKey, token)
|
|
|
+ return Cookies.set(TokenKey, token, { domain: getCookieDomain() })
|
|
|
}
|
|
|
|
|
|
export function removeToken() {
|
|
|
- return Cookies.remove(TokenKey)
|
|
|
+ return Cookies.remove(TokenKey, { domain: getCookieDomain() })
|
|
|
}
|