Description
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:
- In trilium create or choose a note to be your share landing page and set an owned attribute of
#shareRoot
.
- In
./src/services/auth.ts
change line 20 fromres.redirect("login")
tores.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();
}
}
- 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.