lex-xin 3 anni fa
parent
commit
afb9951f01

+ 19 - 3
src/utils/auth.js

@@ -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() })
 }

File diff suppressed because it is too large
+ 0 - 0
web/index.html


File diff suppressed because it is too large
+ 0 - 0
web/static/web/js/app.579a31b9.js


File diff suppressed because it is too large
+ 0 - 0
web/static/web/js/app.b316ea24.js


Some files were not shown because too many files changed in this diff