How can I do silent login on server (m2m) and update local cookie session immediately?

Hi all!

I am using nextjs and nextjs/auth0 package. It is working well but it doesn’t really check the central session state.

If I log out from another website with same issuer, I am still logged in due to local cookie session. ‘refetch’ or ‘refresh’ options don’t help.

I am using SSR and would like to do silent login there and update the session (so if I logged out on website2 it should fail and destroy session and do same in case I am logged out in nextjs app (website1) but logged in on website2. Is it really possible? checkSession method from useUser just calls /api/auth/me.

I can only do silent login on client (it returns proper response or ‘login-required’ error).

I should trigger router redirect to either login/logout after silent check so that local session will be updated based on my research. And it is big UX issue as it means the page will be refreshed each time I do such check.

Any ideas on that? I think it is a really common use-case

Hi @BohdanYavorskyi, and sorry for the late reply!

You could create a custom API endpoint, such as /api/auth/validate-session, that you can use to send the current session to the backend side of your NextJS application. Then, you can call the Management API to check the user’s active session and redirect to the logout if the session is terminated.

Regarding the ‘login-required’ error, we have a knowledge article on that topic, if you would like some help with it.

Please let me know if I can be of more assistance.
Teodor.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.