django - VueJS 应用程序无法在移动浏览器上访问受保护的 API 端点
问题描述
我的 Vue 应用程序在移动浏览器上的使用存在问题。我在 Django 后端有一个受保护的 API 路由,它使用 JWT 进行身份验证/权限。当我进行身份验证时,我将 JWT 保存到 localStorage 和 Vuex,并将其作为来自 Vuex 存储的每个请求(使用 axios)的标头传递。这一切在我的笔记本电脑上都可以正常工作,但在移动设备上访问我的网站时却无法正常工作。使用手机(iOS 12)访问该站点时,我在日志中看到 401 未经授权的错误代码,因此我假设该令牌未作为标头添加。这是我用来附加标题的代码:
import axios from 'axios';
import store from '../store';
const apiCall = axios.create();
apiCall.interceptors.request.use(
config => {
if (store.getters.isAuthenticated) {
// Take the token from the state and attach it to the request's headers
config.headers.Authorization = `JWT ${store.getters.getToken}`;
}
return config
},
error => {
Promise.reject(error)
}
)
export default apiCall;
这是我的开发依赖项:
"devDependencies": {
"@vue/cli-plugin-babel": "^3.0.5",
"@vue/cli-plugin-e2e-nightwatch": "^3.0.5",
"@vue/cli-plugin-eslint": "^3.0.5",
"@vue/cli-plugin-pwa": "^3.0.5",
"@vue/cli-plugin-unit-jest": "^3.0.5",
"@vue/cli-service": "^3.0.5",
"@vue/eslint-config-airbnb": "^3.0.5",
"@vue/test-utils": "^1.0.0-beta.20",
"babel-core": "7.0.0-bridge.0",
"babel-jest": "^23.0.1",
"node-sass": "^4.11.0",
"sass-loader": "^7.0.1",
"vue-template-compiler": "^2.5.17"
},
是否需要添加一些内容才能从移动设备devDependencies
访问?Posts
解决方案
推荐阅读
- c# - 无法在 C# 中解密由 openssl 完成的加密字符串。总是得到 Org.BouncyCastle.Security.InvalidKeyException
- reactjs - 如何使用 React 测试库通过 Ant Design 的 Upload 模拟上传文件?
- python - 我想制作一个可以将pdf发送到我的电子邮件的应用程序
- plantuml - 如何向包含另一个对象的 plantuml 对象添加描述?
- python - 替换字符串列表中给定索引处的部分字符串
- javascript - 我们是否允许在功能组件的 return 之外使用 JSX?
- java - 无法使用 SQLite 数据库和 JDBC 附加第二个数据库
- c - 使用按位运算符重建整数
- api - TFVC api:如何获取文件属性(“可执行文件”和“符号链接”)
- javascript - 反应渲染表 - 将正文数据与标题数据顺序匹配?