Skip to content

Commit

Permalink
Merge branch 'main' into ndom91/cleanup-express-dev-app
Browse files Browse the repository at this point in the history
  • Loading branch information
ndom91 committed May 8, 2024
2 parents fb2d2ba + b7d1f9e commit c2c81db
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 5 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
2 changes: 1 addition & 1 deletion docs/pages/getting-started/adapters/typeorm.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ You can override the default entities and add additional fields with a custom en

1. Create a file containing your modified entities:

```ts filename="lib/entities.ts"
```ts filename="lib/entities.ts" {38-39}
import {
Entity,
PrimaryGeneratedColumn,
Expand Down
2 changes: 1 addition & 1 deletion docs/pages/getting-started/adapters/upstash-redis.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ const defaultOptions = {
Usually changing the `baseKeyPrefix` should be enough for this scenario, but for more custom setups, you can also change the prefixes of every single key.

```ts
export default NextAuth({
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter: UpstashRedisAdapter(redis, { baseKeyPrefix: "app2:" }),
})
```

0 comments on commit c2c81db

Please sign in to comment.