Linking to pages in protected area

I have created a protected area on a website according to the following cookbook recipe:

The protected pages can be found in the subdirectory /closed:

https://mysite.com/closed

About 100 registered users have access to this protected area (Kirby users without panel access). From time to time I inform these users by email about new content in the protected area and send links to this content, e.g.

https://mysite.com/closed/very-interesting-article

When these users click the link in the email and are not logged in, they get to the home page of the website

https://mysite.com/

How could I achieve, that the users get to the login page instead (https://mysite/login), the URL sent by email remains “cached” and the users get to the target URL after entering their credentials?

https://mysite.com/closed/very-interesting-article

Thanks in advance for any advice!

You could simply send them to a route path (let’s call it newshandler, but that’s up to you) and add the redirect to as query string, for example

https://mysite.com/newshandler?user=userid&goto=closed/very-interesting-article

Then in your newshandler route, you check if the user is logged in, if yes, you redirect them to the page using the request parameters.

If the user is not logged in, you send them to the login page, attaching the goto query param, then let the login controller do the rest, i.e. check if a goto query parameter is set and if so, redirect after successful login.

If you don’t have the userid, because you are sending the link as newsletter, then leave out the part with the user, and redirect to login just with the goto arguments.

Of course, what you call the parameters is totally up to you.

1 Like

Great! Thank you very much, Sonja!

Oh, I missed one step, when you send the form, you have to add the query param to a hidden form field, or you store the goto value in the session in step one (the route), and then remove it again when done in the login controller.

Come to think of it, when you leave out the user handling, you might as well send the user straight to the login page with the query parameter, without the additional route.

Thanks again, Sonja!

I took your suggestion, send the users to the login page and attach the destination as a parameter:

https://mysite.com/login?target=very-interesting-article

This works - almost.

The following problem remains: The website in question is bilingual (de/fr). The URL as given above does not work, a URL with language works.

https://mysite.com/de/login?target=very-interesting-article

Do you have any suggestion how to get along without mentioning the language in the URL?

Hm, do you send language specific urls to the users? Do you use the language code for all languages?

I would prefer, not to send language specific URLs. Would be some additional work for approx. 20 of 100 users in France.

Don´t quite understand your second question. The website contains all articles in German and in French, therefore, I use the language codes across the board.

What I meant is if your default language uses the language code in the url or not, so let’s say your default language is German, is the url for the german site mysite.de/de or just mysite.de?

But what I wonder: What was the link your originally wanted to sent the users to? You have to send them to some language version after all?

However, if that doesn’t work, you can still go back to using the original route solution.

Thanks, Sonja,

the URL for the German language site is mysite.org/de, for the French language site mysite.org/fr.

I will stay with sending “de” URLs for the moment and switch to a route solution in version 1.1 of the site.

Thanks again

Thomas