Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirect anonymous bare url to /share page #658

Open
maphew opened this issue Nov 23, 2024 Discussed in #596 · 5 comments
Open

Redirect anonymous bare url to /share page #658

maphew opened this issue Nov 23, 2024 Discussed in #596 · 5 comments

Comments

@maphew
Copy link

maphew commented Nov 23, 2024

Discussed in https://github.com/orgs/TriliumNext/discussions/596

Originally posted by maphew November 15, 2024
How to setup Trilium to redirect bare url to the share page, unless the user is logged in? So an anonymous browser arriving at www.example.net is redirected to www.example.net/share instead of being greeted with the login page.

Or perhaps better, make the share url www.example.net/ and the "I'm editing" url www.example.net/edit ?

preferably using a docker config (so it can be used on PikaPods)

At the technical level, it's actually easy to redirect bare domain to share:

  1. In trilium create or choose a note to be your share landing page and set an owned attribute of #shareRoot.

image

  1. In ./src/services/auth.ts change line 20 from res.redirect("login") to res.redirect("share").
function checkAuth(req: AppRequest, res: Response, next: NextFunction) {
    if (!sqlInit.isDbInitialized()) {
        res.redirect("setup");
    }
    else if (!req.session.loggedIn && !utils.isElectron() && !noAuthentication) {
        #res.redirect("login");
        res.redirect("share");
    }
    else {
        next();
    }
}
  1. Restart Trilium server

To login, edit url in address bar and replace path with '/login', ex: https://my.trilium.net/login

...

This won't work for PikaPods since they only use the lates release stable release from Docker Hub, and making this change in stable needs more thought, work, and documentation.

@maphew
Copy link
Author

maphew commented Nov 23, 2024

As written above, this would be a major change in out of the box Trilium behaviour, so not to be approached lightly. With my recent learning success in adding a whitelist of html tags to the Options page I think I see a path to how to make this an optional setting too. We'll see how well that goes!

I don't know if this is a good approach architecturally speaking, and welcome comments from experienced minds.

maphew added a commit to maphew/trilium that referenced this issue Nov 23, 2024
Redirect works. Must share at least one note and make it `#shareRoot`

Todo:
- explore making this an optional setting in UI
- make the share and login urls customizable
- think about if/where/how to put login link in default share theme
@perfectra1n
Copy link

Would this change require a user to have a root Share note already set up?:

{
  "message": "Share root note not found"
}

I understand the reason why, but IMO since this is firstly a note-taking platform (and not a microblog), I'm not sure if this is the best idea. I understand that your suggestion is what platforms like Wordpress do where the root URL redirects to the website, and /wp-admin is reserved for management/editing. I'm sure @meichthys will have a much more sensible response.

You could do exactly what you're suggesting with access to the webserver and changing its configuration, but since you're on Pikapods I don't believe you have access to that.

@maphew
Copy link
Author

maphew commented Nov 24, 2024

Yes shareRoot needs to be defined, thanks for the reminder! I've added that note to the helper text in the PR

@meichthys
Copy link

First off, I think this is a neat idea, and I can see it's use case, however if it were to be implemented, it would certainly need to be a non-default option.

I would also suspect that there could be some unexpected side effects of a change like this (Elian would have a better understanding on that).

@maphew
Copy link
Author

maphew commented Nov 25, 2024

Thanks for the feedback @meichthys. Yes it's off by default.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants