josx / ra-data-feathers

A feathers rest client for react-admin
MIT License
157 stars 53 forks source link

Match new provider auth signatures v3 #148

Open josx opened 4 years ago

josx commented 4 years ago

According to the v3 blog react admin changed its auth provider signature.

@FacundoMainere Has done a WIP on this

To be done: We still need to be retrocompatible with react-admin v2 (last release just one year ago) and still need to make tests match current signatures.

soullivaneuh commented 3 years ago

I just implemented your library with react-admin v3:

import React from 'react';
import ReactDOM from 'react-dom';
import { Admin, Resource } from 'react-admin';
import { restClient, authClient } from 'ra-data-feathers';
import client from './feathers';
import './index.css';
import reportWebVitals from './reportWebVitals';

import { PostalCodeList } from './resources/postal-codes';

const restClientOptions = {
  id: '_id', // In this example, the database uses '_id' rather than 'id'
  usePatch: true // Use PATCH instead of PUT for updates
};

const authClientOptions = {
  usernameField: 'email',
  passwordField: 'password',
  // permissionsField: 'userroles',
  // redirectTo: '/signin',
}

ReactDOM.render(
  <Admin
    dataProvider={restClient(client, restClientOptions)}
    authProvider={authClient(client, authClientOptions)}
  >
    <Resource
      name="postal-codes"
      list={PostalCodeList}
    />
  </Admin>,
  document.getElementById('root')
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();

The login process works (the authenticate method is successful) but I am immediately logged out just after that.

Is that related to this issue?

soullivaneuh commented 3 years ago

This basic and not complete custom implementation works:

const authProvider: AuthProvider = {
  login: (params) => client.authenticate({
    strategy: 'local',
    email: params.username,
    password: params.password,
  }),
  logout: () => client.logout().then(() => Promise.resolve()),
  checkAuth: () => client
    .reAuthenticate()
    .then(() => Promise.resolve())
    .catch(() => Promise.reject({ redirectTo: '/login' })),
  checkError: () => Promise.resolve(),
  getPermissions: () => Promise.resolve(),
}
josx commented 3 years ago

I dont understand if there is any error using react.-admin v3. I suppose it is working well, but would be great if you can make effort on assure it and/or add more testing.

sagannotcarl commented 3 years ago

I'm having trouble getting this to work. Does anyone have a more complete working example? I tried swapping out the authClient from here https://github.com/josx/ra-data-feathers/pull/146 but I keep getting the same error: `client.logout is not a function."

josx commented 3 years ago

I dont understand what are you needing. Can you explain a little more?