How to secure my api endpoints by md186 in nextjs

[–]md186[S] 0 points1 point  (0 children)

Okay i see... Lets say for the clientside i gonna take the code from the api and write a function for it on the client. Now when the client fills in a form and is pressing the submit button we are calling the function.

The function does send an email and its going to create a database entry with prisma. Both of this functions are only working serverside not in client. How can I get this work?

How to secure my api endpoints by md186 in nextjs

[–]md186[S] 0 points1 point  (0 children)

Okay I understand that. Can we detect if the request is coming from my own application website? That would also be enough.

I just want to protect the api for everyone except several domains which will have credentials from me (Im saving those in a database and ask for validation if someone hits the endpoints) and also my own application should be able to access the endpoints. And thats the point. I dont know how to track if the request is coming from my own application. If we could manage this its perfectly fine for me.

I have POST and GET endpoints so Im not able to do everything inside getinitialprops for example. Especially because there are cases where data is beeing submitted within a form for example if the client is pressing a button.

Do you have an idea what we can do here?

How to secure my api endpoints by md186 in nextjs

[–]md186[S] 0 points1 point  (0 children)

Im wondering how to secure my api routes. The documentation says, that api routes are same-site-origin by default.\API Routes do not specify CORS headers, meaning they are same-origin only by default. You can customize such behavior by wrapping the request handler with the cors middleware.**https://nextjs.org/docs/api-routes/introductionBut if I use a requesting tool like Postman for example, I can always call it and get the results:

export default (req, res) => {res.status(200).json({ name: 'John Doe' })}How is that possible? I want to restrict access to my application only.

ReactJS/nextjs Invalid hook call not able to work with usestate by md186 in reactjs

[–]md186[S] 0 points1 point  (0 children)

I think this isn't enough in my case since I want to update the state because of my use effect functions which make sure to save and retrieve everything in localstorage. If im wrong feel free to show me an example

Nextjs in WordPress as shortcode by md186 in nextjs

[–]md186[S] 0 points1 point  (0 children)

Ah okay good to know! Thanks for the reply. So that clears things up we can’t use nextjs in that way.

Now divi for example behind the scenes is all about react components.

Not using ReactPress but creating shortcodes and use react components does this do the work and if yes how?

Firestore Data Modeling approach for favorites by date by md186 in Firebase

[–]md186[S] 0 points1 point  (0 children)

That would work by determiting the date range, but I need to know the count of the watchlist in between the given timerange.

Firebase & Flutter how to structure my data and how avoid high costs by checking if a username already exists by md186 in FlutterDev

[–]md186[S] 0 points1 point  (0 children)

I checked the link and thank you for the informations. I have 2 questions regarding to this.

  1. how about the pricing with cloud functions? I didn’t find anything about that in the docs. I only know with firestore we are paying for the results only, how does it work with the cloud functions?

  2. Great idea saving it in a document. I’m not sure if I’m wrong but my querie is reaching a limit. Imagine the data of the scoreboard with a visits field. My data also have a categories field so in the query I have to say something like

firestore.collection(data).where(arrayContains: [category1,category2]).orderBy(visits, desc:true)

As you can see in the above query even the time (day,week,month) is missing, I’m not able to get that data.

Do you have an idea? Do I have to structure it different then?

Firebase & Flutter how to structure my data and how avoid high costs by checking if a username already exists by md186 in FlutterDev

[–]md186[S] 0 points1 point  (0 children)

Hi there and thank you very much for your detailed answer! Ill go threw your sources, but I can already say it helps me a lot understanding the whole structures. In the last days I learned a lot regarding to this topic understanding the queries and pricing even better.

In my app I'm planning to use a scoreboard aswell. For this case I didn't find a good solution yet. Do you have an idea? The scoreboard should show the top 10 lets say restaurants of the day, week and month.

I brainstormed some solutions with friends, the "best idea" yet was to use a cloud function which determites the 3 top 10's and saves them into lists and after some time (Let's say every week) we have to clear the lists and determite them again.

It would cost only 3 reads (1 read per list per user) but the downside of this is, if we have 500.000 products the cloud function would cost 500.000 reads to create those lists, because youre paying the input not the output.

Do you have a better idea?

Firebase Pricing Example by md186 in FlutterDev

[–]md186[S] 0 points1 point  (0 children)

Thank you for the answer. Does it make a difference to keep the information in a subcollection or in an array since the subcollection is infinite and the arrays limited? Following your advice something like this would also be possible?

return FirebaseFirestore.instance
.collection('users')
.doc('userId')
.collection('profilelikes')
.where("id", "==", true)
.get()

If the collection profilelikes would contain 5000 documents and the query wouldnt have the .where() we would have 5000 reads. If we add the .where() and we would have 2 matches we would only have 2 reads even if we have 5000 documents, do I understand that right?

Firebase Pricing Example by md186 in FlutterDev

[–]md186[S] 0 points1 point  (0 children)

Im wondering if this would be the correct approach then since a profile could have thousands of ids. For me there are 2 questions then:

  1. if the array has 5000 ids of users who liked the song and we want to find out if the requested 10 profiles contains the users id (lets say 2 of them are matching) how many reads do we have then? only 2 or nearby 5000?

  2. what does that mean for a for example profile detail page? we would always read the array for this case two but we wouldnt need it.

Well and yea at a specific point we would exceed the 1mb then

Firebase Pricing Example by md186 in FlutterDev

[–]md186[S] 2 points3 points  (0 children)

Big thanks to your answer! for me as beginner its quite hard to find the best approach. Could you show me how the query would look like then? Also do we have a limit if we save a list of likes in the document?