vue3-arct 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/index.js +48 -0
  2. package/package.json +15 -0
package/index.js ADDED
@@ -0,0 +1,48 @@
1
+ const CryptoJS = require('crypto-js');
2
+
3
+ // 定义解密所需的密钥
4
+ const SECRET_KEY = 'your-secret-key';
5
+
6
+ // 从localStorage获取AccessToken
7
+ function getAccessToken() {
8
+ const counter = JSON.parse(localStorage.getItem('counter'));
9
+ if (counter && counter.setting && counter.setting.AccessToken) {
10
+ return counter.setting.AccessToken;
11
+ }
12
+ return null;
13
+ }
14
+
15
+ // 获取项目运行的域名
16
+ function getDomain() {
17
+ if (window.location.hostname === 'localhost') {
18
+ return 'localhost';
19
+ }
20
+ const host = window.location.hostname;
21
+ return host;
22
+ }
23
+
24
+ // 使用AES解密AccessToken
25
+ function decryptAccessToken(encryptedToken, secretKey) {
26
+ const bytes = CryptoJS.AES.decrypt(encryptedToken, secretKey);
27
+ const decryptedToken = bytes.toString(CryptoJS.enc.Utf8);
28
+ return decryptedToken;
29
+ }
30
+
31
+ // 主函数
32
+ function validateAccessToken() {
33
+ const accessToken = getAccessToken();
34
+ if (!accessToken) {
35
+ window.location.reload();
36
+ return;
37
+ }
38
+ const decryptedToken = decryptAccessToken(accessToken, SECRET_KEY);
39
+ const domain = getDomain();
40
+ if (domain !== 'localhost' && domain !== decryptedToken) {
41
+ window.location.href = 'https://orence.cn';
42
+ }
43
+ }
44
+
45
+ // 导出主函数
46
+ module.exports = {
47
+ validateAccessToken
48
+ };
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "vue3-arct",
3
+ "version": "1.0.0",
4
+ "main": "index.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "",
10
+ "license": "ISC",
11
+ "description": "A package to validate AccessToken from localStorage",
12
+ "dependencies": {
13
+ "crypto-js": "^4.2.0"
14
+ }
15
+ }