RSC cookie cache
Hey guys,
In the context of a nextjs app, I'm wondering how to handle this:
https://www.better-auth.com/docs/integrations/next#rsc-and-server-actions
I've enabled cookie cache and it works fine, I can see the session_data cookie being set once I've logged in. However when the cookie expires (per the maxAge setting), how do you go about refreshing the cookie cache?
I mean, yeah, the quoted part does clearly say that I need to interact with the server from within a server action or route handler...
But in a practical sense, how do you actually go about orchestrating that?
I was thinking of writing a wrapper around fetch/my serverApi utility. This would be a server action that calls getSession with the asResponse option and if the set-cookie header is present, I would set the cookie on the cookieStore obtained from next via await cookies()...
But I dunno, seems a bit hacky...
I was wondering if anyone ran into this and had a good pattern for handling it. Thanks in advance!
In the context of a nextjs app, I'm wondering how to handle this:
As RSCs cannot set cookies, the cookie cache will not be refreshed until the server is interacted with from the client via Server Actions or Route Handlers.
https://www.better-auth.com/docs/integrations/next#rsc-and-server-actions
I've enabled cookie cache and it works fine, I can see the session_data cookie being set once I've logged in. However when the cookie expires (per the maxAge setting), how do you go about refreshing the cookie cache?
I mean, yeah, the quoted part does clearly say that I need to interact with the server from within a server action or route handler...
But in a practical sense, how do you actually go about orchestrating that?
I was thinking of writing a wrapper around fetch/my serverApi utility. This would be a server action that calls getSession with the asResponse option and if the set-cookie header is present, I would set the cookie on the cookieStore obtained from next via await cookies()...
But I dunno, seems a bit hacky...
I was wondering if anyone ran into this and had a good pattern for handling it. Thanks in advance!