ra-data-feathers icon indicating copy to clipboard operation
ra-data-feathers copied to clipboard

Match new provider auth signatures v3

Open josx opened this issue 3 years ago • 5 comments

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.

josx avatar Jul 10 '20 13:07 josx

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 avatar Dec 14 '20 13:12 soullivaneuh

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(),
}

soullivaneuh avatar Dec 14 '20 14:12 soullivaneuh

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.

josx avatar Dec 14 '20 20:12 josx

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."

sagannotcarl avatar Jul 13 '21 16:07 sagannotcarl

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

josx avatar Jul 26 '21 17:07 josx