Documentation
¶
Overview ¶
Package store provides a small local SQLite database for user names and password hashes, used for login and registration.
Index ¶
- func BootstrapFromEnv(adminUser, adminPassword string) error
- func CreateToken(userId string) (string, error)
- func CreateUser(username, password string) (userId string, err error)
- func GetUserIdByUsername(username string) string
- func GetUsernameByUserId(userId string) string
- func HasAnyUser() (bool, error)
- func Open(path string) error
- func UserIdExists(id string) bool
- func ValidateToken(token string) string
- func VerifyUser(username, password string) bool
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func BootstrapFromEnv ¶
BootstrapFromEnv creates the first user from SYNC_ADMIN_USER and SYNC_ADMIN_PASSWORD if the DB has no users.
func CreateToken ¶
CreateToken creates a session token for the user (by userId) and returns it. Caller must store it.
func CreateUser ¶
CreateUser adds a user with the given password (hashed with bcrypt). Returns userId (UUID). If user already exists, returns their id and nil.
func GetUserIdByUsername ¶
GetUserIdByUsername returns the user's id (UUID) or empty string if not found.
func GetUsernameByUserId ¶
GetUsernameByUserId returns the username (email) for the given userId, or empty string if not found.
func HasAnyUser ¶
HasAnyUser returns true if at least one user exists (for bootstrap).
func Open ¶
Open opens the auth SQLite database at path (creates file and dirs if needed). Safe to call once.
func UserIdExists ¶
UserIdExists returns true if the id exists in users.
func ValidateToken ¶
ValidateToken returns the user id if the token is valid and not expired, else empty string.
func VerifyUser ¶
VerifyUser returns true if the username exists and the password matches.
Types ¶
This section is empty.