Skip to content

Redirect anonymous bare url to /share page #5282

Closed
@maphew

Description

@maphew

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions