Can't access HTTPS api using axios with email/password

Hi Team,

I’m not able to access https api using axios from react application but it works when I use the Realm SDK.






I have changed the app settings to allow access from http://localhost:3000

also when I remove the email/password from headers in the ajax request, I get this instead.

const ajaxConfig = {
    headers: {
      Authorization: `Bearer ${_accessToken}`,
    },
  };

  React.useEffect(() => {
    // const data = await user.functions.getAnything('abc');
    // console.log('Realm SDK', data);
    axios.get(usersUrl, ajaxConfig).then((res) => {
      console.log('AXIOS => ', res.data);
    });
  });

Hello @Mohammed_Ramadan

Is the error you are experiencing, according to the screenshot attached, a CORS error?

Please, be aware that credential headers like email and password are useful for infrequent or test requests. However, we strongly encourage you to authenticate requests using an Authorization Header from a web browser to avoid CORS errors.

Nevertheless, is there any reason to not use the web SDK with GraphQL in your React Realm App?

Please let me know if you have any additional questions or concerns regarding the details above.

Kind Regards,
Josman

Hi @Josman_Perez_Exposit

Thanks for your answer. the reason to not use web SDK is i’m trying realm for the first time and in case I want to change the backend, then I would need to change the API route. Regarding Authorization header. It doesn’t work with me as you can see in the image above i’m passing the headers option to axios but it doesn’t work. And I don’t want to use GraphQL

@Josman_Perez_Exposit
here is one example I have just did as simple GET request.


error: "no authentication methods were specified"
error_code: "InvalidParameter"

Hi @Josman_Perez_Exposit .

I just saw your reply for similar issue here Different authorization approaches for HTTPS endpoint vs GraphQL endpoint - #6 by Josman_Perez_Exposit
:frowning: but i’m so sad

i’m really really really sad guys. Realm as backend as a service is truly simple, easy and I came from AWS for few reasons and now i’m thinking to go back :frowning: