---
title: Integrate Auth.js with Tiger Data | Tiger Data Docs
description: Store Auth.js users, accounts, and sessions in Tiger Cloud or self-hosted TimescaleDB using the official PostgreSQL adapter.
---

[Auth.js](https://authjs.dev/) (formerly NextAuth.js) is an open-source authentication library that handles sign-in, sessions, and account management for web applications across many frameworks and providers.

This page shows you how to integrate Auth.js with Tiger Data using the official [PostgreSQL adapter](https://authjs.dev/getting-started/adapters/pg), so that Auth.js persists users, accounts, and sessions in your service or database instead of an external store.

In this integration guide, you:

- Create the tables that Auth.js requires in your service or database.
- Configure the PostgreSQL adapter in your application to connect to Tiger Data.
- Verify that authentication data is persisted.

## Prerequisites for this integration guide

To follow these steps, you'll need:

- A [Tiger Cloud service](/get-started/quickstart/create-service/index.md), or a running instance of [self-hosted TimescaleDB](/get-started/choose-your-path/install-timescaledb/index.md).

* Your [connection details](/integrate/find-connection-details/index.md).

- A [Next.js](https://nextjs.org/docs/app/getting-started/installation) application using Auth.js v5 (`next-auth@beta`). Auth.js also supports Qwik, SvelteKit, and Express, with equivalent configuration.
- [Node.js](https://nodejs.org/) and a package manager such as npm, pnpm, yarn, or bun.

## Create the Auth.js schema in your service or database

The PostgreSQL adapter expects four tables: `users`, `accounts`, `sessions`, and `verification_token`. Because Tiger Cloud and self-hosted TimescaleDB are built on PostgreSQL, the adapter works against them with no changes.

1. **Connect to your service or database**

   Connect to your service or database with your [connection details](/integrate/find-connection-details/index.md), using `psql` or the SQL editor of your choice.

2. **Create the Auth.js tables**

   Run the following SQL to create the schema the adapter expects:

   ```
   CREATE TABLE verification_token (
     identifier TEXT NOT NULL,
     expires TIMESTAMPTZ NOT NULL,
     token TEXT NOT NULL,
     PRIMARY KEY (identifier, token)
   );


   CREATE TABLE accounts (
     id SERIAL,
     "userId" INTEGER NOT NULL,
     type VARCHAR(255) NOT NULL,
     provider VARCHAR(255) NOT NULL,
     "providerAccountId" VARCHAR(255) NOT NULL,
     refresh_token TEXT,
     access_token TEXT,
     expires_at BIGINT,
     id_token TEXT,
     scope TEXT,
     session_state TEXT,
     token_type TEXT,
     PRIMARY KEY (id)
   );


   CREATE TABLE sessions (
     id SERIAL,
     "userId" INTEGER NOT NULL,
     expires TIMESTAMPTZ NOT NULL,
     "sessionToken" VARCHAR(255) NOT NULL,
     PRIMARY KEY (id)
   );


   CREATE TABLE users (
     id SERIAL,
     name VARCHAR(255),
     email VARCHAR(255),
     "emailVerified" TIMESTAMPTZ,
     image TEXT,
     PRIMARY KEY (id)
   );
   ```

   Run `\dt` in `psql` to confirm that all four tables exist.

## Configure the adapter in your application

Point Auth.js at your service or database, then wire the adapter into your Auth.js configuration.

1. **Install the adapter and the PostgreSQL driver**

   In your application directory, install the PostgreSQL adapter and the `pg` driver:

   Terminal window

   ```
   npm install @auth/pg-adapter pg
   ```

2. **Set your connection environment variables**

   Add your [connection details](/integrate/find-connection-details/index.md) to your environment, for example in `.env.local`:

   Terminal window

   ```
   DATABASE_HOST=<host>
   DATABASE_NAME=<dbname>
   DATABASE_USER=<user>
   DATABASE_PASSWORD=<password>
   ```

   Note

   Auth.js also requires an `AUTH_SECRET` and at least one configured authentication provider. See [Auth.js installation](https://authjs.dev/getting-started/installation) for the base setup.

3. **Configure Auth.js to use the adapter**

   Create `./auth.ts` and pass a `pg` connection pool to `PostgresAdapter`:

   ```
   import NextAuth from "next-auth"
   import PostgresAdapter from "@auth/pg-adapter"
   import { Pool } from "pg"


   const pool = new Pool({
     host: process.env.DATABASE_HOST,
     user: process.env.DATABASE_USER,
     password: process.env.DATABASE_PASSWORD,
     database: process.env.DATABASE_NAME,
     max: 20,
     idleTimeoutMillis: 30000,
     connectionTimeoutMillis: 2000,
   })


   export const { handlers, auth, signIn, signOut } = NextAuth({
     adapter: PostgresAdapter(pool),
     providers: [],
   })
   ```

   Add your authentication providers to the `providers` array. Auth.js now reads and writes session and account data through your service or database.

## Verify the integration

To confirm Auth.js is persisting data in your service or database:

1. **Sign in through your application**

   Start your application with `npm run dev`, open it in a browser, and complete a sign-in with one of your configured providers.

2. **Query your service or database to confirm the data arrived**

   Connect to your service or database and query the `users` table:

   ```
   SELECT id, name, email FROM users;
   ```

   You see a row for the account you just signed in with, confirming that Auth.js is writing authentication data to Tiger Data.

You have successfully integrated Auth.js with Tiger Data.

## Troubleshooting

- **`relation "users" does not exist`:** create the Auth.js schema before starting your application. Run the SQL in [Create the Auth.js schema](#create-the-authjs-schema-in-your-service-or-database).
- **`column "userId" does not exist`:** the adapter relies on case-sensitive, double-quoted column names. Create the tables with the exact SQL above so the quoted identifiers match.

For other connectivity and authentication issues, see [Troubleshoot Tiger Cloud integrations](/integrate/troubleshooting/index.md).

## Next steps

[Find your connection details](/integrate/find-connection-details/index.md)

[Locate the host, port, database, user, and password for your service or database.](/integrate/find-connection-details/index.md)

[Connect your app](/integrate/code/connect-your-app/index.md)

[Connect to your database from your preferred programming language.](/integrate/code/connect-your-app/index.md)
