android - 为Android构建时FeathersJS登录错误
问题描述
我正在使用 Ionic 构建一个 Android 应用程序。并使用以下feathers_client.js
const feathers = require('@feathersjs/feathers');
const socketio = require('@feathersjs/socketio-client');
const auth = require('@feathersjs/authentication-client');
const io = require('socket.io-client');
const socket = io('http://mydomain.example:3030');
const feathers_client = feathers();
feathers_client
.configure(socketio(socket))
.configure(auth({ storage: window.localStorage }));
module.exports = feathers_client;
当我在浏览器上运行应用程序时,它工作正常。但是当我在 Android 设备上运行它时,我只会得到“NotAuthenticated”。
我假设这是因为 FeathersJS 将 JWT 令牌存储在 window.localStorage 并且这在 Android 应用程序用户空间中不可用。
两个问题:
1)有没有办法告诉 FeathersJS 将此令牌存储在其他地方?
2)如果没有,有人遇到过这种情况并可以为我提供解决方案吗?
顺便说一句,这是我的身份验证代码:
export class SSHSettingsPage implements OnInit {
public inputEmail: string;
public inputPassword: string;
constructor() { }
ngOnInit() {
}
public performLogin($event) {
let authObj: object = { "strategy": "local", "email": this.inputEmail, "password": this.inputPassword};
client.authenticate(authObj)
.then(res => {
console.log(res);
window.localStorage.setItem("user",JSON.stringify(res.user));
window.location.href = "/download";
})
.catch(err => {
console.log(err);
window.location.href = "/login-error";
})
}
}
解决方案
正如配置 API中提到的,该storage
选项可以传递一个React Native AsyncStorage的实例:
import {AsyncStorage} from 'react-native';
// Available options are listed in the "Options" section
app.configure(auth({
storage: AsyncStorage
}))
推荐阅读
- vb.net - 获取顶部/左侧位置的 PixelColor 以更改屏幕保护程序上的时间字符串
- python - 连续值> 100的序列平均长度(Python)
- audio - 在 ffmpeg 中为实时提要的音频流添加延迟
- c - Idk 如何从 .dat 文件中获取信息并使用 C 从中创建单个链表
- apache-spark - 消耗 500 个 Kafka 主题并编写 Parquet 的最佳策略是什么?
- javascript - 使用 JSON 数据的类中的 Javascript 递归
- android - 如何从模型类列表字符串值中设置私有静态字符串值
- java - 创建一个扩展 Java.util.ArrayList 的类
- python - 使用signals.py创建用户时自动创建Django Profile
- swiftui-list - SwiftUI - 如何在编辑模式下避免列表中的行缩进,但不使用 onDelete?(附代码/视频)