我正在使用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;当我在浏览器上运行这个应用程序时,它工作得很好。但是当我在安卓设备上运行它时,我只能得到"NotAuthenticated“。
我认为这是因为FeathersJS将JWT令牌存储在window.localStorage上,而这在安卓应用程序用户空间中是不可用的。
两个问题:
( 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";
})
}
}发布于 2020-02-11 16:37:53
正如在配置API中提到的,storage选项可以传递给反应本地AsyncStorage的一个实例
import {AsyncStorage} from 'react-native';
// Available options are listed in the "Options" section
app.configure(auth({
storage: AsyncStorage
}))https://stackoverflow.com/questions/60154992
复制相似问题