lvtpb

package module
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 5, 2026 License: MIT Imports: 21 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package lvtpb serves live LiveTemplate pages from a PocketBase app.

Register serves every pages/*.tmpl at /<name>, a live table for each collection at /<collection>, and the sign-in, sign-up, sign-out and password reset pages. A page shows what PocketBase's REST API would show the signed-in user: the collection's list rule applies on the first read and on every change.

PocketBase moved off GitHub, so its module path is ganigeorgiev.com/pocketbase/pocketbase.

Things to know before production

Set the app URL in PocketBase's settings to an https:// URL, or set Config.SecureCookies. The auth and reset cookies get the Secure flag only then, also behind a proxy that ends TLS.

PocketBase's rate limiter covers these pages only when its rules name their paths, for example "POST /signin", "POST /signup" and "POST /forgot-password". Every form posts to its own page's path.

Signing out deletes the cookie. A PocketBase token stays valid until it expires, so a copied cookie keeps working until then. A password change ends every token of that account and closes its open pages.

A page reads the signed-in user once, when it connects. A change to that user that affects a list rule, such as a new role, shows after the page reconnects or reloads.

The sign-in page signs in with an email and a password only, whatever identity fields the collection allows. It does not fire PocketBase's auth request hooks (OnRecordAuthRequest), so an app that audits sign-ins there does not see these.

The sign-up page shows PocketBase's own validation errors, so it tells whether an email already has an account, as PocketBase's REST API does. The sign-in and reset pages do not.

A live page refuses a collection whose list rule reads @request.headers, @request.query or @request.body: a page has no request, so the rule would see empty values.

A page holds every row the list rule allows, in insertion order. There is no paging yet.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Register

func Register(app core.App, cfg Config)

Register serves the app's pages and the sign-in pages from app. Call it before app.Start.

Types

type Config

type Config struct {
	// Pages holds the app's page templates. A file "tasks.tmpl" serves /tasks.
	// A page that has the name of a collection lists it as .Live.<name>. A
	// file with the name of a default template (index.tmpl, layout.tmpl,
	// signin.tmpl, signup.tmpl, collection.tmpl, forgot-password.tmpl,
	// reset-password.tmpl) replaces the default; index.tmpl serves /.
	Pages fs.FS

	// AuthCollection is the auth collection that users sign in to.
	// Default: "users".
	AuthCollection string

	// CookieName is the cookie that holds the PocketBase auth token.
	// Default: "pb_auth".
	CookieName string

	// SecureCookies gives the auth and reset cookies the Secure flag even
	// when the app URL in PocketBase's settings is not https://, for an app
	// behind a proxy that ends TLS.
	SecureCookies bool
}

Config configures Register.

type Event

type Event struct {
	Action string `json:"action"`
	Record Row    `json:"record"`
	Resync bool   `json:"-"`
}

Event is one change from PocketBase's realtime broker. Resync means events were dropped, so the page reads the rows again.

type Row

type Row = map[string]any

Row is one record as a page sees it: the fields that PocketBase's API would return to this user, keyed by field name ("id", "title", ...).

type State

type State struct {
	// Auth is the signed-in user, or nil.
	Auth Row
	// Live holds the rows of each live collection, by collection name.
	Live map[string][]Row
	// Collection and Fields describe the collection of the generic page.
	Collection string
	Fields     []string
}

State is the data of every lvtpb page.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL