How to handle session expiration in custom Nextcloud app like built-in apps (Files, Calendar, Contacts)?

I’ve developed a custom Nextcloud app, and I’m trying to implement proper session expiration handling.

In built-in apps like Files, Calendar, and Contacts, when a user’s session expires, they are either redirected to the login page or prompted to log in again. I would like to achieve the same behavior in my app — ensuring that users are redirected to the login page if their session has expired.

Could someone guide me on the recommended approach to handle this the “Nextcloud way”? Is there a built-in middleware, annotation, or controller pattern I should be using to avoid repeating login checks manually in every controller method?

Thanks in advance!

You do not have to worry about this. There are middlewares in place that impose the most strict user requirements (only admin with CSRF etc is allowed). You have to/can loosen these to e.g. allow regular users to use the app.

So, if you did not define a page as #[PublicPage], if the session times out, the user will be redirected to the login form.

1 Like

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