LibSQL + JWT Auth

LibSQL + JWT Generation + Example in Go

Deploy LibSQL + JWT Auth

libsql

railtools/libsql

Just deployed

/data

Deploy and Host LibSQL + JWT Auth on Railway

LibSQL + JWT Auth is a minimal starter template that runs a libsql server with JWT authentication enabled by default. It includes a Go client, a keypair/token generator (jwtgen.go), and a working query demo (main.go).

About Hosting LibSQL + JWT Auth

This template spins up a LibSQL server with JWT auth pre-configured via SQLD_AUTH_JWT_KEY. No setup needed — just deploy and connect with a signed token. Comes with Go code to generate your own keys and test the connection.

NOTE: JWT authentication is enabled by default with a pre-generated keypair and example token.

Common Use Cases

  • Secure embedded DB for internal tools or edge apps
  • Lightweight alternative to Postgres/MySQL with auth
  • LibSQL testing with JWT tokens enabled

Dependencies for LibSQL + JWT Auth Hosting

  • Go 1.21+ (for main.go and jwtgen.go), only used to generate key pairs
  • LibSQL server

Deployment Dependencies

External Docs

Example: Go Client

package main

import (
	"context"
	"database/sql"
	"fmt"
	"log"

	_ "github.com/tursodatabase/libsql-client-go/libsql"
)

func main() {
	const appDomain = "libsql-production-b53d.up.railway.app"
	const authToken = "eyJhbGciOi..." // Replace with your JWT

	dsn := fmt.Sprintf("libsql://%s?authToken=%s", appDomain, authToken)
	db, err := sql.Open("libsql", dsn)
	if err != nil {
		log.Fatalf("open failed: %v", err)
	}
	defer db.Close()

	ctx := context.Background()
	db.ExecContext(ctx, `DROP TABLE IF EXISTS users`)
	db.ExecContext(ctx, `CREATE TABLE users (id INTEGER PRIMARY KEY, name TEXT)`)
	db.ExecContext(ctx, `INSERT INTO users (name) VALUES ('Alice'), ('Bob')`)

	rows, _ := db.QueryContext(ctx, `SELECT id, name FROM users ORDER BY id`)
	defer rows.Close()
	for rows.Next() {
		var id int
		var name string
		rows.Scan(&id, &name)
		fmt.Printf("User %d: %s\n", id, name)
	}
}

Why Deploy LibSQL + JWT Auth on Railway?

Railway is a singular platform to deploy your infrastructure stack. Railway will host your infrastructure so you don't have to deal with configuration, while allowing you to vertically and horizontally scale it.

By deploying LibSQL + JWT Auth on Railway, you are one step closer to supporting a complete full-stack application with minimal burden. Host your servers, databases, AI agents, and more on Railway.


Template Content

More templates in this category

View Template
Foundry Virtual Tabletop
A Self-Hosted & Modern Roleplaying Platform

View Template
(v1) Simple Medusa Backend
Deploy an ecommerce backend and admin using Medusa

View Template
peppermint
Docker-compose port for peppermint.sh