Issue in updating next-auth session data
Answered
Crazy ant posted this in #help-forum
Crazy antOP
I am using
How to update next-auth session data when database is updated.
When database is updated, I need to login again to reflect the updated data. my backend code is separate, I am making a post request using fetch to an api end point and I could update database successfully. But updated data does not reflect to my current session I need to logout and login for that. Please help.
getServerSession in server component and useSession in client component to fetch data from session.How to update next-auth session data when database is updated.
When database is updated, I need to login again to reflect the updated data. my backend code is separate, I am making a post request using fetch to an api end point and I could update database successfully. But updated data does not reflect to my current session I need to logout and login for that. Please help.
Answered by B33fb0n3
You can update your session only clientside like this: https://next-auth.js.org/getting-started/client#updating-the-session
Keep in mind to validate the new object on server before saving.
Keep in mind to validate the new object on server before saving.
3 Replies
@Crazy ant I am using `getServerSession` in server component and `useSession` in client component to fetch data from session.
How to update next-auth session data when database is updated.
When database is updated, I need to login again to reflect the updated data. my backend code is separate, I am making a post request using fetch to an api end point and I could update database successfully. But updated data does not reflect to my current session I need to logout and login for that. Please help.
You can update your session only clientside like this: https://next-auth.js.org/getting-started/client#updating-the-session
Keep in mind to validate the new object on server before saving.
Keep in mind to validate the new object on server before saving.
Answer
Crazy antOP
@B33fb0n3 Thanks
happy to help