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

How to handle auth?

Open 2ZZ opened this issue 5 years ago • 1 comments

Hi, It's great to see active development on this.

I want to use Postgraphile's JWT auth alongside ra-data-postgraphile, but I can't figure out how to handle a 401 from the API as the page loads. The app doesn't seem to reach my auth provider code as Apollo throws the error below.

Unhandled Rejection (Error): Network error: Response not successful: Received status code 401
new ApolloError
C:/Users/drive/Desktop/sparking/src/errors/ApolloError.ts:46
  43 | // Constructs an instance of ApolloError given a GraphQLError
  44 | // or a network error. Note that one of these has to be a valid
  45 | // value or the constructed error will be meaningless.
> 46 | constructor({
     | ^  47 |   graphQLErrors,
  48 |   networkError,
  49 |   errorMessage,

Is it possible to use this project alongside a JWT protected Postgraphile?

BTW this is using the repo's example code

import React, { useEffect, useState } from "react";
import { Admin, Resource, Loading } from "react-admin";
import pgDataProvider from "ra-data-postgraphile";

const App = () => {
  const [dataProvider, setDataProvider] = useState(null);

  useEffect(() => {
    (async () => {
      const dataProvider = await pgDataProvider({
        uri: "http://localhost:5433/graphql",
        options: {
          resources: {
            Company: {
              pluralizedName: "Companies"
            }
          }
        }
      });
      setDataProvider(dataProvider);
    })();
  }, []);

  if (!dataProvider) {
    return <Loading />;
  }
  return (
    <Admin dataProvider={dataProvider}>
      <Resource name="Company" />
    </Admin>
  );
};

export default App;

2ZZ avatar Feb 18 '20 21:02 2ZZ

sorry for the long delay @2ZZ this repo's issue tracker has been somehow disabled and re-enabled today and your request got lost.

i guess all you need is to define an authProvider for your <Admin> (see https://marmelab.com/react-admin/Admin.html#authprovider)

frisi avatar Dec 10 '21 10:12 frisi