Next.js Discord

Discord Forum

Fetching with on demand revalidation

Answered
Rhinelander posted this in #help-forum
Open in Discord
RhinelanderOP
Is this good for singleton that will fetch my data from CMS api or is there any other way that is more optimal?
Answered by B33fb0n3
You might want to build somewhere an authentication for your endpoint. Because currently everyone can revalidate the page. That isn’t a problem for the data of the page, but more a performance issue. So think about checking like a token, a password, … in your handler 🙂
View full answer

32 Replies

You might want to build somewhere an authentication for your endpoint. Because currently everyone can revalidate the page. That isn’t a problem for the data of the page, but more a performance issue. So think about checking like a token, a password, … in your handler 🙂
Answer
The rest seems good for me ^^
RhinelanderOP
How would I do that?
I located that in my utils/
it is not in app/api/router
So doesn't that hide it?
As far as I understand api/router is public and everyone can see what your fetching
But if i locate that somewhere else or even i just rename router to something like fetcher that is hidden right?
So am I good? Or should I authenticate? I am new to this so sorry if I have stupid questions... @B33fb0n3
RhinelanderOP
The second photo is utlis/api/getSocialLinks.js and facebook is one of those links so for posts i would do api/getPosts.js and do same thing
Is that stupid or ok
Blog must be superfast and seo freindly
I don't know if i am slowing down stuff with this
or if is even secure
ok and the getSocialLinks is public and calls the fetcher, right?
RhinelanderOP
it is in utils so i don't think anyone can see it??? But also everything is protected by strapi api token...
this is the whole structure i call fetcher 4 times in getSocialLinks.js
But also everything is protected by strapi api token...
ah then everything is fine, if it's protected by a secret key ^^
RhinelanderOP
yeah
so this code is good?
fast secure ?
"Good" is subjective. I would do it differently, but your way is also a possible way, if it works
RhinelanderOP
How would you do it?
I don't think that I am able to understand every if you would tell me
RhinelanderOP
sure then i will use this one until i find better solution
yea. I my case the docs helped me a lot while guiding through this process
RhinelanderOP
Thanks tho... you helped a lot
cool, please mark solution