Turso Per User Starter

R
Renaudil y a 2 jours
0

Description

Demo multi-tenancy with the Turso Platforms API

npx boilerapp turso-per-user-starter

文档

Turso Per User Starter

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

Turso Per User Starter Template

Demo

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

https://turso-per-user-starter.vercel.app

Get Started

Deploy your own Turso powered platform in a few easy steps...

  • Create a Database

    • Once the database is created, you'll be presented with details about your database, and Connect details
    • Note down the following (you'll need these later):
      • Database name
      • Org name
      • Group Token (Create Group Token -> Create Token)
      • Platform API Token (Create Platform API Token -> Insert memorable name -> Create Token))
  • Sign up to Clerk

    • Create a new application from the dashboard
    • Note down the following (you'll need these later):
      • Public key
      • Secret key
  • Deploy with Vercel

    • Add the following environment variables (from the details you noted down earlier):
      • NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY - Clerk public key
      • CLERK_SECRET_KEY - Clerk secret key
      • TURSO_API_TOKEN - Platform API Token
      • TURSO_ORG - Org name
      • TURSO_DATABASE_NAME - Database name
      • TURSO_GROUP_AUTH_TOKEN - Group Token
    • Click Deploy and you're done!

You may optionally set up webhooks to automate the creation of databases in the background — learn more.

Local Development

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

  1. <details> <summary>Clone this repository</summary>

    Begin by cloning this repository to your machine:

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

    Run the following:

    cp .env.example .env
    npm install
    
    </details>
  3. <details> <summary>Create a new Turso database with Turso</summary>

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

    turso db create <database-name>
    

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

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

    TURSO_ORG=
    TURSO_DATABASE_NAME=
    

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

    </details>
  4. <details> <summary>Create a new group token</summary>

    Run the following:

    turso group tokens create <database-name>
    

    Now update .env to include the group token:

    TURSO_GROUP_AUTH_TOKEN=
    

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

    </details>
  5. <details> <summary>Run database migrations</summary>

    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.

    </details>
  6. <details> <summary>Create a new Turso API Token</summary>

    Run the following:

    turso auth api-tokens mint clerk
    

    Then set the API token in the .env file:

    TURSO_API_TOKEN=
    
</details>
  1. <details> <summary>Configure Clerk</summary>

    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=
    
    </details>
  2. <details> <summary>Run the application</summary>

    Run the following:

    npm run dev
    

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

    </details>

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.

Tech Stack

Need help?

  1. Open an issue on GitHub
  2. Submit a Pull Request to improve this repo
  3. Join us on Discord

Prix

Gratuit

FREE

评论 (0)

常见问题

常见问题解答 (FAQ)

有问题?我们有答案。如果您找不到想要的答案,请随时联络我们。

Boilerapp 是一个专门用于分享 Boilerplates、入门套件(Starter Kits)和项目模版的开发者社区平台。我们的目标很简单:为您节省初始配置(Setup)的时间,让您可以专注于真正重要的代码。无论您是在寻找简单的代码库还是完整的 SaaS 项目,都能在这里找到。

还有其他问题?

我们的团队随时为您提供帮助。联络我们,我们将尽快回复。