使用 React 的 Cors 和使用 DEVISE 的 Rails 的问题

问题描述 投票:0回答:0

我在 api 中通过设计进行 Sign_out 时遇到问题。

我们开始吧...我有一个 React 应用程序和一个 Rails-API 后端。

我从我的API调用各种方法,一些获取,一些帖子......等等。

即使使用 devise 自己的 gem,我也可以创建一个帐户,然后毫无问题地登录。

现在我去实现sign_out和boom! CORS 错误。

const logOut = async(event) => {
     const url = `${process.env.REACT_APP_API_URL}/auth/sign_out`;

     const requestOptions = {
       method: 'DELETE',
       headers: {
         'Content-Type': 'application/json',
         'access-token': Cookies.get('access-token'),
         'client': Cookies.get('client'),
         'uid': Cookies.get('user_email')
       }
     };

     const res = await fetch(url, requestOptions).then();
     console.log(res); // doesn't even get here
}

当我单击调用函数 logOut 的按钮时,出现错误:

Uncaught runtime errors:
ERROR
Failed to fetch
TypeError: Failed to fetch
     at logOut (http://localhost:3002/static/js/bundle.js:378:23)
     at chainedFunction (http://localhost:3002/static/js/bundle.js:95443:9)
     at HTMLUnknownElement.callCallback (http://localhost:3002/static/js/bundle.js:58759:18)
     at Object.invokeGuardedCallbackDev (http://localhost:3002/static/js/bundle.js:58803:20)
     at invokeGuardedCallback (http://localhost:3002/static/js/bundle.js:58860:35)
     at invokeGuardedCallbackAndCatchFirstError (http://localhost:3002/static/js/bundle.js:58874:29)
     at executeDispatch (http://localhost:3002/static/js/bundle.js:63018:7)
     at processDispatchQueueItemsInOrder (http://localhost:3002/static/js/bundle.js:63044:11)
     at processDispatchQueue (http://localhost:3002/static/js/bundle.js:63055:9)
     at dispatchEventsForPlugins (http://localhost:3002/static/js/bundle.js:63064:7)

编辑----------

请求调用甚至没有到达 API。 我一直关注 API,但调用根本就没有到达。

—不是评论

reactjs ruby-on-rails devise cors
© www.soinside.com 2019 - 2024. All rights reserved.