Authentication "cannot fetch"

84 Views Asked by At

So im trying to implement this Auth API with admin-on-rest. I've tried to follow the auth guide, but get stuck when I come to "Sending Credentials to the REST API". I can see the incoming request in the terminal, but I get "cannot fetch" when i try to login.

My authClient.js looks like this:

import { AUTH_LOGIN } from 'admin-on-rest';

export default (type, params) => {
    if (type === AUTH_LOGIN) {
        const { email, password } = params;
        const request = new Request('http://localhost:3090/signin', {
            method: 'POST',
            body: JSON.stringify({ email, password }),
            headers: new Headers({ 'Content-Type': 'application/json' }),
        })
        return fetch(request)
            .then(response => {
                if (response.status < 200 || response.status >= 300) {
                    throw new Error(response.statusText);
                }
                return response.json();
            })
            .then(({ token }) => {
                localStorage.setItem('token', token);
            });
    }
    return Promise.resolve();
}

In what way would i need to change the Auth API to make this work?

0

There are 0 best solutions below