fix: 移除axios拦截器中硬编码的desk_calendar认证头
移除axios请求拦截器中为desk_calendar接口强制设置的硬编码User-Id和User-Token 在登录逻辑中添加认证头设置功能,从登录响应中获取并设置User-Id和User-Token
Showing
2 changed files
with
11 additions
and
7 deletions
| ... | @@ -2,7 +2,7 @@ | ... | @@ -2,7 +2,7 @@ |
| 2 | * @Author: hookehuyr hookehuyr@gmail.com | 2 | * @Author: hookehuyr hookehuyr@gmail.com |
| 3 | * @Date: 2022-05-28 10:17:40 | 3 | * @Date: 2022-05-28 10:17:40 |
| 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com | 4 | * @LastEditors: hookehuyr hookehuyr@gmail.com |
| 5 | - * @LastEditTime: 2025-12-25 09:56:58 | 5 | + * @LastEditTime: 2025-12-26 14:09:39 |
| 6 | * @FilePath: /mlaj/src/utils/axios.js | 6 | * @FilePath: /mlaj/src/utils/axios.js |
| 7 | * @Description: | 7 | * @Description: |
| 8 | */ | 8 | */ |
| ... | @@ -53,12 +53,6 @@ axios.interceptors.request.use( | ... | @@ -53,12 +53,6 @@ axios.interceptors.request.use( |
| 53 | config.headers['User-Token'] = user_info.HTTP_USER_TOKEN; | 53 | config.headers['User-Token'] = user_info.HTTP_USER_TOKEN; |
| 54 | } | 54 | } |
| 55 | 55 | ||
| 56 | - // NOTE: 特殊处理 a=desk_calendar 接口, 强制使用指定的 User-Id 和 User-Token | ||
| 57 | - if ((config.params && config.params.a === 'desk_calendar') || (config.url && config.url.includes('a=desk_calendar'))) { | ||
| 58 | - config.headers['User-Id'] = '1033954'; | ||
| 59 | - config.headers['User-Token'] = 'WN2BD9XQ7CRSVQ92FMB62V9C9OHHRBL38L2NS4GJ#1033954#50'; | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | // const url_params = parseQueryString(location.href); | 56 | // const url_params = parseQueryString(location.href); |
| 63 | // GET请求默认打上时间戳,避免从缓存中拿数据。 | 57 | // GET请求默认打上时间戳,避免从缓存中拿数据。 |
| 64 | const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; | 58 | const timestamp = config.method === 'get' ? (new Date()).valueOf() : ''; | ... | ... |
| ... | @@ -88,6 +88,8 @@ import { ref, computed, onMounted } from 'vue' | ... | @@ -88,6 +88,8 @@ import { ref, computed, onMounted } from 'vue' |
| 88 | import { useRouter, useRoute } from 'vue-router' | 88 | import { useRouter, useRoute } from 'vue-router' |
| 89 | import { showToast } from 'vant' | 89 | import { showToast } from 'vant' |
| 90 | import { useTitle } from '@vueuse/core' | 90 | import { useTitle } from '@vueuse/core' |
| 91 | +import { setAuthHeaders } from "@/utils/axios"; | ||
| 92 | + | ||
| 91 | // 导入接口 | 93 | // 导入接口 |
| 92 | import { smsAPI } from '@/api/common' | 94 | import { smsAPI } from '@/api/common' |
| 93 | import { loginAPI, userInfoAPI } from '@/api/recall_users' | 95 | import { loginAPI, userInfoAPI } from '@/api/recall_users' |
| ... | @@ -178,6 +180,14 @@ const handleLogin = async () => { | ... | @@ -178,6 +180,14 @@ const handleLogin = async () => { |
| 178 | try { | 180 | try { |
| 179 | const res = await loginAPI({ mobile: phone.value, sms_code: code.value }) | 181 | const res = await loginAPI({ mobile: phone.value, sms_code: code.value }) |
| 180 | if (res.code) { | 182 | if (res.code) { |
| 183 | + // 获取data里面的 user_id, HTTP_USER_TOKEN, 并设置到后面所有的请求头里面,headers.User-Id, headers.User-Token | ||
| 184 | + const { user_id, HTTP_USER_TOKEN } = res?.data?.user_info || {}; | ||
| 185 | + if (user_id && HTTP_USER_TOKEN) { | ||
| 186 | + // 设置认证请求头 | ||
| 187 | + setAuthHeaders(user_id, HTTP_USER_TOKEN); | ||
| 188 | + // 缓存user_info | ||
| 189 | + localStorage.setItem('user_info', JSON.stringify(res?.data?.user_info || {})); | ||
| 190 | + } | ||
| 181 | const userInfo = await userInfoAPI() | 191 | const userInfo = await userInfoAPI() |
| 182 | // 登录之后需要判断是否有完善个人信息 | 192 | // 登录之后需要判断是否有完善个人信息 |
| 183 | if (userInfo.code) { | 193 | if (userInfo.code) { | ... | ... |
-
Please register or login to post a comment