Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

don`t Work #12

Open
devalexandre opened this issue Mar 18, 2020 · 0 comments
Open

don`t Work #12

devalexandre opened this issue Mar 18, 2020 · 0 comments

Comments

@devalexandre
Copy link

I try use it

App.js

import React from 'react';
import { apiUrl } from './config';
import { Admin, Resource ,fetchUtils} from 'react-admin';
import Strapi from 'strapi-sdk-javascript/build/main';
import strapiDataProvider from 'ra-dp-strapi';
import { ProductList,ProductCreate,ProductEdit } from './products';
import authProvider from './authProvider';

const httpClient = (url, options = {}) => {
  if (!options.headers) {
      options.headers = new Headers({ Accept: 'application/json' });
  }
  const token = localStorage.getItem('token');
  options.headers.set('Authorization', `Bearer ${token}`);
  return fetchUtils.fetchJson(url, options);
};

const strapi = new Strapi(apiUrl);

const App = () => (
<Admin authProvider={authProvider} dataProvider={strapiDataProvider(strapi,httpClient)}>
      <Resource name="products" list={ProductList} create={ProductCreate} edit={ProductEdit}/>
  </Admin>
);

export default App;

authProvider.js

export default {
    // called when the user attempts to log in
    login: ({ username }) => {
        localStorage.setItem('username', username);
        // accept all username/password combinations
        return Promise.resolve();
    },
    // called when the user clicks on the logout button
    logout: () => {
        localStorage.removeItem('username');
        return Promise.resolve();
    },
    // called when the API returns an error
    checkError: ({ status }) => {
        if (status === 401 || status === 403) {
            localStorage.removeItem('username');
            return Promise.reject();
        }
        return Promise.resolve();
    },
    // called when the user navigates to a new location, to check for authentication
    checkAuth: () => {
        return localStorage.getItem('username')
            ? Promise.resolve()
            : Promise.reject();
    },
    // called when the user navigates to a new location, to check for permissions / roles
    getPermissions: () => Promise.resolve(),
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant