#having cors error while fetching from client side

35 messages · Page 1 of 1 (latest)

robust monolith
#

The error Access to fetch at 'https://api.minaexplorer.com/accounts/B62qqCvKnFKM3jUbPL92fZseNYA2kVSaU694GJucFScJadnTXre3Exy' from origin 'http://localhost:3001' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

neon mirageBOT
#

🔎 This post has been indexed in our web forum and will be seen by search engines so other users can find it outside Discord

🕵️ Your user profile is private by default and won't be visible to users outside Discord, if you want to be visible in the web forum you can add the "Public Profile" role in id:customize

✅ You can mark a message as the answer for your post with Right click -> Apps -> Mark Solution
(if you don't see the option, try refreshing Discord with Ctrl + R)

robust monolith
#

The code

#

@ashen shell

#

this is the one I am talking about

ashen shell
#

Yeah you need to have 'use server' on top not 'use client'. But the problem for you here would be that you are using some sort of a crypto wallet which from my experience require 'use client'. So either you make a new file with 'use server' and export a function from there into that file or I think you can also just add 'use server' inside a function in the same file by writing it right under the function declaration above where the function code would go

robust monolith
ashen shell
#

And the function should just return the value

#

Like for example getAccountBalance.tsx
:ts 'use server' export const getAccountBalance = async(accounts) =>{ const apiUrl = `https://api.minaexplorer.com/accounts/${accounts}`; const response = await fetch(apiUrl, { method: 'GET', headers: { 'Content-Type': 'application/json', // Add any headers you need }, }); if(response.ok){ const data = await response.json(); return(data); } else{ console.log("Error"); } }

And then you just import it in the file you sent above like:

import getAccountBalance from getAccountBalance.tsx```
robust monolith
#

haa got it , let me try it out

ashen shell
#

Keep me posted

robust monolith
ashen shell
robust monolith
#

I can update

robust monolith
#

I am checking the docs it isn't mentioned any place

robust monolith
ashen shell
robust monolith
#

yaa do you know what exactly I amsuppose ot add in the config

ashen shell
robust monolith
# ashen shell

oh okay was this mentioned in the docs the link provided did not even mention this

ashen shell
robust monolith
#

I might have to see if I cna upgrade an existing next js project to 14

ashen shell
#

You can

#

Just change the version in package.json to v14 and do npm update

robust monolith
ashen shell
#

If the console says that when you updated just ignore it

robust monolith
ashen shell
#

No problem 👍

sand sequoia
#

If You want to upload image without extra traffic, You do it from client side - so there still should be solution to make requests from client without CORS problem.

robust monolith
#

I have recently deployed another rpogram to vercel

#

and facing the cors issue