资源路径上的页面刷新会导致应用程序注销

时间:2017-08-31 15:22:51

标签: feathersjs admin-on-rest

在页面重新加载时,应用程序不会为API调用重新加载JWT令牌。 重新加载仪表板路径效果很好但在资源路径上失败。

我不确定我们如何配置feather-client这样做。

````

//feathersClient.js
import feathers from 'feathers-client';

const host = 'http://localhost:3030';

export default feathers()
    .configure(feathers.hooks())
    .configure(feathers.rest(host).fetch(window.fetch.bind(window)))
    .configure(feathers.authentication({ jwtStrategy: 'jwt', storage: window.localStorage }));

//authClient.js
import { authClient } from 'aor-feathers-client';
import feathersClient from './ApiClient/feathersClient';

const authClientOptions = {
    storageKey: 'feathers-jwt',
    authenticate: { strategy: 'local' },
};

export default authClient(feathersClient, authClientOptions)

//App.js
import React from 'react';
import { Admin, Resource } from 'admin-on-rest';
import { Delete } from 'admin-on-rest/lib/mui'
import apiClient from './ApiClient'
import authClient from './authClient'
import Dashboard from './components/Dashboard'
import { ProjectList, ProjectCreate, ProjectShow, ProjectEdit } from './components/Projects'
import { PeopleList, PeopleCreate, PeopleShow, PeopleEdit } from './components/Peoples'

const App = () => (
    <Admin
        authClient={authClient}
        restClient={apiClient}
        title="SWP by Akoya"
        dashboard={Dashboard}>
        <Resource name="projects"
            list={ProjectList}
            create={ProjectCreate}
            show={ProjectShow}
            edit={ProjectEdit}
            remove={Delete}/>
    </Admin>
)

export default App

1 个答案:

答案 0 :(得分:2)

查看React chat example。它显示了如何使用local authentication或首先尝试使用the stored token进行身份验证。

// client.js
import io from 'socket.io-client';
import feathers from 'feathers/client';
import hooks from 'feathers-hooks';
import socketio from 'feathers-socketio/client';
import authentication from 'feathers-authentication-client';

const socket = io('http://localhost:3030');
const client = feathers();

client.configure(hooks());
client.configure(socketio(socket));
client.configure(authentication({
  storage: window.localStorage
}));

export default client;

然后

client.authenticate()
  // Authentication with stored token was successful
  .then(() => showApplication())
  // Authentication failed. Show login page
  .catch(error => showLogin());