2017-08-31 57 views
0

應用程序不會在頁面重新加載時重新加載API調用的JWT令牌。 在Dashboard路徑上重新裝載效果良好,但在資源路徑上失敗。資源路徑上的頁面刷新導致應用程序註銷

我不確定要了解配置羽毛客戶端的方式。

````

//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 

回答

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()); 
+0

在管理上,rest'的'的背景下,這可能意味着,''的AOR的羽毛,client'包authClient'應該調用認證處理時'AUTH_CHECK'類型 – Gildas

+0

事實上,它與我用來將admin-on-rest連接到羽毛api的庫相關:https://github.com/josx/aor-feathers-client/issues/39。謝謝 – Fonzarely