Skip to content

Commit

Permalink
chore(docs): cleanup Drizzle adapter doc page
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed May 8, 2024
1 parent aecc221 commit 09a3691
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions docs/pages/getting-started/adapters/drizzle.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ import {
} from "drizzle-orm/pg-core"
import postgres from "postgres"
import { drizzle } from "drizzle-orm/postgres-js"
import type { AdapterAccountType } from "@auth/core/adapters"
import type { AdapterAccountType } from "next-auth/adapters"

const connectionString = "postgres://postgres:postgres@localhost:5432/drizzle"
const pool = postgres(connectionString, { max: 1 })
Expand Down Expand Up @@ -130,7 +130,7 @@ import {
} from "drizzle-orm/mysql-core"
import mysql from "mysql2/promise"
import { drizzle } from "drizzle-orm/mysql2"
import type { AdapterAccountType } from "@auth/core/adapters"
import type { AdapterAccountType } from "next-auth/adapters"

export const connection = await mysql.createConnection({
host: "host",
Expand Down Expand Up @@ -209,7 +209,7 @@ If you want to modify the schema or add additional fields, you can use the follo
import { integer, sqliteTable, text, primaryKey } from "drizzle-orm/sqlite-core"
import { createClient } from "@libsql/client"
import { drizzle } from "drizzle-orm/libsql"
import type { AdapterAccountType } from "@auth/core/adapters"
import type { AdapterAccountType } from "next-auth/adapters"

const client = createClient({
url: "DATABASE_URL",
Expand Down Expand Up @@ -328,6 +328,30 @@ app.use(
</Code.Express>
</Code>

#### Passing your own Schemas

If you want to use your own tables, you can pass them as a second argument to `DrizzleAdapter`.

- The `sessionsTable` is optional and only required if you're using the database session strategy.
- The `verificationTokensTable` is optional and only required if you're using a Magic Link provider.

```ts filename="auth.ts"
import NextAuth from "next-auth"
import Google from "next-auth/providers/google"
import { DrizzleAdapter } from "@auth/drizzle-adapter"
import { db, accounts, sessions, users, verificationTokens } from "./schema"

export const { handlers, auth } = NextAuth({
adapter: DrizzleAdapter(db, {
usersTable: users,
accountsTable: accounts,
sessionsTable: sessions,
verificationTokensTable: verificationTokens,
}),
providers: [Google],
})
```

### Migrating your database

With your schema now described in your code, you'll need to migrate your database to your schema. An example `migrate.ts` file looks like this. For more information, check out Drizzle's migration [quick start guide](https://orm.drizzle.team/docs/migrations).
Expand Down

0 comments on commit 09a3691

Please sign in to comment.