Next.js Discord

Discord Forum

please help with authentication flow

Unanswered
Pteromalid wasp posted this in #help-forum
Open in Discord
Pteromalid waspOP
i want to verify the cookie to make sure the session is still valid, i call my server action in page.jsx BUT if there's an error i can not delete the cookie...how am i supposed to manage this???

like page.jsx:
check for existence of session token
if exists, call verifySession server action
can't delete the cookie in this function, can't return an error and delete the cookie in page.jsx (WHAT DO I DO???)
if valid, fetch data, pass to client wrapper or straight to client component

i don't want to rely on middleware to verify the token because i also need to know if i'm deleting it so i can notify the user that they are being logged out. this is so frustrating and it feels like it's difficult for no reason

Edit: I guess I can pass the verify session error to like a client wrapper and delete the cookie in that but seems like a janky workaround

3 Replies