qdmp-cli 0.0.6 → 0.0.7

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/api.js +16 -6
  2. package/package.json +1 -1
package/api.js CHANGED
@@ -16,9 +16,16 @@ const API_CONFIG = {
16
16
  * 基础请求函数
17
17
  * @param {string} url - 请求地址
18
18
  * @param {object} options - 请求选项
19
+ * @param {string} env - 环境
20
+ * @param {boolean} needAuth - 是否需要认证头,默认为true
19
21
  * @returns {Promise} 请求结果
20
22
  */
21
- export const request = async (url, options = {}, env = "prod") => {
23
+ export const request = async (
24
+ url,
25
+ options = {},
26
+ env = "prod",
27
+ needAuth = true
28
+ ) => {
22
29
  const config = {
23
30
  baseURL:
24
31
  env === "prod"
@@ -28,10 +35,12 @@ export const request = async (url, options = {}, env = "prod") => {
28
35
  headers: { ...API_CONFIG.headers },
29
36
  ...options,
30
37
  };
31
- // 添加认证头(如果有 token)
32
- const token = getToken();
33
- if (token) {
34
- config.headers["authorization"] = `Bearer ${token}`;
38
+ // 添加认证头(如果需要且如果有 token)
39
+ if (needAuth) {
40
+ const token = getToken();
41
+ if (token) {
42
+ config.headers["authorization"] = `Bearer ${token}`;
43
+ }
35
44
  }
36
45
 
37
46
  try {
@@ -66,7 +75,8 @@ export const login = async (username, password, env = "prod") => {
66
75
  method: "POST",
67
76
  body: JSON.stringify({ username, password }),
68
77
  },
69
- env
78
+ env,
79
+ false // 登录时不需要认证头
70
80
  );
71
81
  if (result?.data?.token) {
72
82
  saveToken(result.data.token); // 保存token
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qdmp-cli",
3
- "version": "0.0.6",
3
+ "version": "0.0.7",
4
4
  "description": "qdmp-cli",
5
5
  "main": "index.js",
6
6
  "type": "module",