Will next-auth fetch the account information from API every-time I page refreshes or changes?
Or maybe useSession or getServerSession call?
If it does how can I prevent this, because I am using discord provider and even with a 1/2 users using the website its getting 429 Ratelimited very often.
Code of my auth.ts
10 Replies
This callback is called whenever a JSON Web Token is created (i.e. at sign in) or updated (i.e whenever a session is accessed in the client). The returned value will be encrypted, and it is stored in a cookie.
Callbacks | NextAuth.js
Callbacks are asynchronous functions you can use to control what happens when an action is performed.
from the docs
and every time you access something
you fetch the guilds from discord
from what I knew,
Makes it only execute on the first sign in
the main thing is
"whenever a session is accessed in the client"
On next jwt call account and user is not present so the code inside it will never get called untill log out and log in
so it will return the old token
So where do I fetch the guilds
on client
you can use react query to fetch and keep state
just remember to disable the updates on the query
otherwise there will be a lots of issues related to that
Discord Developer Portal
Discord Developer Portal — API Docs for Bots and Developers
Integrate your service with Discord — whether it's a bot or a game or whatever your wildest imagination can come up with.
you can check in the response headers the limit
but that kind of info shouldn't be requested that soon
Can I use the module lru-cache on the fetchGuilds method to do it?