---
title: "Deploy LibSQL + JWT Auth"
description: "LibSQL + JWT Generation + Example in Go"
category: "Other"
url: https://railway.com/deploy/libsql-jwt-auth
---

# Deploy LibSQL + JWT Auth

LibSQL + JWT Generation + Example in Go

**[Deploy LibSQL + JWT Auth on Railway](https://railway.com/template/libsql-jwt-auth)**

- **Creator:** PollyWolly's Projects
- **Category:** Other
- **Total deploys:** 21

## Template content

### libsql

- **Source:** railtools/libsql
- **Public domain:** Yes

## Documentation

# 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`).

Eject the template, read the README.md and start connecting to your database. Or checkout [https://github.com/railtools/libsql](https://github.com/railtools/libsql)

## 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

- [LibSQL / sqld docs](https://docs.turso.tech/reference/server/introduction)

### External Docs

- [LibSQL / sqld docs](https://docs.turso.tech/reference/server/introduction)

## Example: Go Client

```go
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 = "eyJhbGciOiJFZERTQSIsInR5cCI6IkpXVCJ9.eyJleHAiOjQ5MDYwMTg5NTQsInN1YiI6InVzZXIifQ.GaOet8Jv_WOUYEv71oSp-ps0XfJAzAkQY34W3zxAcE70xFZa8KRGpkt4ql-7IDXBHwVWpckHnynMgthsBpghDg" // 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.

## Similar templates

- [Rocky Linux](https://railway.com/deploy/rocky-linux) — Hosted Rocky Linux 9 workspace with SSH and persistent storage. 🚀
- [Foundry Virtual Tabletop](https://railway.com/deploy/X5tR6G) — A Self-Hosted & Modern Roleplaying Platform
- [Letta Code Remote](https://railway.com/deploy/letta-code-remote) — Run a Letta Code agent 24/7. No inbound ports, just deploy.

Open this page in a browser: https://railway.com/deploy/libsql-jwt-auth
