首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >为Android构建时FeathersJS登录错误

为Android构建时FeathersJS登录错误
EN

Stack Overflow用户
提问于 2020-02-10 16:59:19
回答 1查看 64关注 0票数 0

我正在使用Ionic构建一个Android应用程序。并使用以下feathers_client.js

代码语言:javascript
复制
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)如果没有,有人面对这种情况,可以给我一个解决办法吗?

顺便说一句,这是我的认证代码:

代码语言:javascript
复制
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";
    })
  }

}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-02-11 16:37:53

正如在配置API中提到的,storage选项可以传递给反应本地AsyncStorage的一个实例

代码语言:javascript
复制
import {AsyncStorage} from 'react-native';

// Available options are listed in the "Options" section
app.configure(auth({
  storage: AsyncStorage
}))
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/60154992

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档