notrab / turso-per-user-starter

Database per user

Home Page:https://turso-platforms-starter.vercel.app

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Turso Per User Starter

A Next.js application that demonstrates how to use the Turso Platforms API to create a database per user.

Turso Platforms Starter

Demo

The app below uses a database per user, and is powered by Turso.

https://turso-platforms-starter.vercel.app

Prerequisites

Get Started

Start building your Turso powered platform in a few simple steps...

  1. Clone this repository

    Begin by cloning this repository to your machine:

    git clone https://github.com/notrab/turso-per-user-starter.git
    cd turso-per-user-starter
  2. Install dependencies and initialize .env

    Run the following:

    cp .env.example .env
    npm install
  3. Create a new SQLite schema database with Turso

    Follow the instructions to install the Turso CLI, and then run the following:

    turso db create <database-name> --type schema

    Alternatively, you can sign up on the web, and create a new schema database from there.

    Now update .env to include your organization, and schema database name:

    TURSO_ORG_NAME=
    TURSO_SCHEMA_DATABASE_NAME=

    The TURSO_ORG_NAME can be your personal username, or the name of any organization you have with other users.

  4. Create a new group token

    Run the following:

    turso group tokens create <database-name>

    Now update .env to include the group token:

    TURSO_DATABASE_GROUP_AUTH_TOKEN=

    If you didn't already have one, a new group will be created for you with the name default.

  5. Run database migrations

    Run the following:

    npm run db:migrate

    If you make changes to db/schema.ts, make sure to run npm run db:generate to create the migrations, and npm run db:migrate to apply them.

  6. Create a new Turso API Token

    Run the following:

    turso auth api-tokens mint clerk

    Then set the API token in the .env file:

    TURSO_USER_API_TOKEN=
  1. Configure Clerk

    Sign up to Clerk and create a new application.

    Add your Clerk public key and secret key to the .env file:

    NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY=
    CLERK_SECRET_KEY=
  2. Run the application

    Run the following:

    npm run dev

    Now open http://localhost:3000 with your browser to try out the app!

Optional: Webhook setup

You can automate the creation of databases per user in the background with webhooks.

Read the wiki for more information on how to set up webhooks with Clerk during development, and production.

Deploy to Production

Make sure you have a database setup (following the steps above), the database has been migrated, and you have the environment variables available.

Deploy with Vercel

If you're using webhooks, make sure to update Clerk with the production URL. You will need to know the Vercel production deployment ahead of time, or re-deploy once you have it.

Read the wiki

Tech Stack

Need help?

Join us on Discord

About

Database per user

https://turso-platforms-starter.vercel.app


Languages

Language:TypeScript 98.7%Language:JavaScript 1.0%Language:CSS 0.3%