question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Authentication won't work:

See original GitHub issue

By having next setup:

import { AUTH_LOGIN, AUTH_LOGOUT, AUTH_CHECK } from 'admin-on-rest';

export const authClient = (type, params) => {
    if (type === AUTH_LOGIN) {
        const { username, password } = params;
        localStorage.setItem('username', username)
        localStorage.setItem('token', btoa(username + ":" + password));
        return Promise.resolve();
    }
    if (type === AUTH_LOGOUT) {
        localStorage.removeItem('username');
        localStorage.removeItem('token');
        return Promise.resolve();
    }
    if (type === AUTH_CHECK) {
        return localStorage.getItem('username') ? Promise.resolve() : Promise.reject();
    }
    return Promise.reject('Unkown method');
};

And :

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

class App extends Component {
  render() {
    return (
      <Admin  authClient={authClient} dashboard={Dashboard} restClient={restClient}> 
...

Getting 401 error every-time during call to API

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:10 (6 by maintainers)

github_iconTop GitHub Comments

4reactions
fzaninottocommented, Jun 2, 2017

The CORS headers must be set on your API endpoint. There is nothing specific to admin-on-rest here that we could document, because admin-on-rest only deals with the client side.

If you want instructions on how to do that, just google “setup cors headers”.

0reactions
fzaninottocommented, Dec 11, 2018

@louizaOU we don’t provide support via GitHub issues, please post your question on StackOverflow.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Common problems with two-step verification for a work or ...
First, make sure you typed the password correctly. If that doesn't fix it, try creating a new app password for the app. Do...
Read more >
Fix common issues with 2-Step Verification - Google Support
My Google Authenticator codes don't work · On your Android device, go to the main menu of the Google Authenticator app. · Tap...
Read more >
How to Fix Google Authenticator Codes That Have Stopped ...
How to Fix Google Authenticator Codes That Have Stopped Working · 1. Sync the App's Time · 2. Update the Authenticator App ·...
Read more >
What should I do if I've activated 2FA, but lost access to the ...
What should I do if I've activated 2FA, but lost access to the authentication app or it is not working? There are several...
Read more >
Troubleshoot login with two-factor authentication on Facebook
If you don't have access to your phone, or you no longer have access to your two-factor authentication method, select I don't have...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found