mirror of
https://github.com/SrIzan10/next-auth.git
synced 2026-05-01 10:55:20 +00:00
misc
This commit is contained in:
@@ -262,7 +262,7 @@ const docusaurusConfig = {
|
||||
},
|
||||
],
|
||||
typedocAdapter("Dgraph"),
|
||||
typedocAdapter("Drizzle"),
|
||||
typedocAdapter("Drizzle ORM"),
|
||||
typedocAdapter("DynamoDB"),
|
||||
typedocAdapter("Fauna"),
|
||||
typedocAdapter("Firebase"),
|
||||
|
||||
@@ -9,18 +9,18 @@
|
||||
* ## Installation
|
||||
*
|
||||
* ```bash npm2yarn2pnpm
|
||||
* npm install next-auth drizzle-orm @next-auth/drizzle-adapter
|
||||
* npm install next-auth drizzle-orm @auth/drizzle-adapter
|
||||
* npm install drizzle-kit --save-dev
|
||||
* ```
|
||||
*
|
||||
* @module @next-auth/drizzle-adapter
|
||||
* @module @auth/drizzle-adapter
|
||||
*/
|
||||
import {
|
||||
accounts,
|
||||
users,
|
||||
sessions,
|
||||
verificationTokens,
|
||||
type Thing,
|
||||
type DrizzleClient,
|
||||
} from "./schema"
|
||||
import { and, eq } from "drizzle-orm/expressions"
|
||||
import type { Adapter } from "next-auth/adapters"
|
||||
@@ -33,7 +33,7 @@ import type { Adapter } from "next-auth/adapters"
|
||||
* ```js title="pages/api/auth/[...nextauth].js"
|
||||
* import NextAuth from "next-auth"
|
||||
* import GoogleProvider from "next-auth/providers/google"
|
||||
* import { DrizzleAdapter } from "@next-auth/drizzle-adapter"
|
||||
* import { DrizzleAdapter } from "@auth/drizzle-adapter"
|
||||
* import { db } from "./db-schema"
|
||||
*
|
||||
* export default NextAuth({
|
||||
@@ -114,7 +114,7 @@ import type { Adapter } from "next-auth/adapters"
|
||||
* ```
|
||||
*
|
||||
**/
|
||||
export function DrizzleAdapter(client: Thing): Adapter {
|
||||
export function DrizzleAdapter(client: DrizzleClient): Adapter {
|
||||
return {
|
||||
createUser(data) {
|
||||
return client
|
||||
|
||||
@@ -1,51 +1,63 @@
|
||||
import { integer, sqliteTable, text, primaryKey } from 'drizzle-orm/sqlite-core';
|
||||
import { drizzle } from 'drizzle-orm/better-sqlite3';
|
||||
import { migrate } from 'drizzle-orm/better-sqlite3/migrator';
|
||||
import Database from 'better-sqlite3';
|
||||
import { ProviderType } from 'next-auth/providers';
|
||||
import { integer, sqliteTable, text, primaryKey } from "drizzle-orm/sqlite-core"
|
||||
import { drizzle } from "drizzle-orm/better-sqlite3"
|
||||
import { migrate } from "drizzle-orm/better-sqlite3/migrator"
|
||||
import Database from "better-sqlite3"
|
||||
import { ProviderType } from "next-auth/providers"
|
||||
|
||||
const sqlite = new Database('db.sqlite');
|
||||
const sqlite = new Database("db.sqlite")
|
||||
|
||||
export const users = sqliteTable('users', {
|
||||
id: text('id').notNull().primaryKey(),
|
||||
name: text('name'),
|
||||
export const users = sqliteTable("users", {
|
||||
id: text("id").notNull().primaryKey(),
|
||||
name: text("name"),
|
||||
email: text("email").notNull(),
|
||||
emailVerified: integer("emailVerified", { mode: "timestamp_ms" }),
|
||||
image: text("image"),
|
||||
});
|
||||
})
|
||||
|
||||
export const accounts = sqliteTable("accounts", {
|
||||
userId: text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
type: text("type").$type<ProviderType>().notNull(),
|
||||
provider: text("provider").notNull(),
|
||||
providerAccountId: text("providerAccountId").notNull(),
|
||||
refresh_token: text("refresh_token"),
|
||||
access_token: text("access_token"),
|
||||
expires_at: integer("expires_at"),
|
||||
token_type: text("token_type"),
|
||||
scope: text("scope"),
|
||||
id_token: text("id_token"),
|
||||
session_state: text("session_state"),
|
||||
}, (account) => ({
|
||||
nameDoesntMatter: primaryKey(account.provider, account.providerAccountId)
|
||||
}))
|
||||
export const accounts = sqliteTable(
|
||||
"accounts",
|
||||
{
|
||||
userId: text("userId")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
type: text("type").$type<ProviderType>().notNull(),
|
||||
provider: text("provider").notNull(),
|
||||
providerAccountId: text("providerAccountId").notNull(),
|
||||
refresh_token: text("refresh_token"),
|
||||
access_token: text("access_token"),
|
||||
expires_at: integer("expires_at"),
|
||||
token_type: text("token_type"),
|
||||
scope: text("scope"),
|
||||
id_token: text("id_token"),
|
||||
session_state: text("session_state"),
|
||||
},
|
||||
(account) => ({
|
||||
nameDoesntMatter: primaryKey(account.provider, account.providerAccountId),
|
||||
})
|
||||
)
|
||||
|
||||
export const sessions = sqliteTable("sessions", {
|
||||
sessionToken: text("sessionToken").notNull().primaryKey(),
|
||||
userId: text("userId").notNull().references(() => users.id, { onDelete: "cascade" }),
|
||||
userId: text("userId")
|
||||
.notNull()
|
||||
.references(() => users.id, { onDelete: "cascade" }),
|
||||
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
||||
})
|
||||
|
||||
export const verificationTokens = sqliteTable("verificationToken", {
|
||||
identifier: text("identifier").notNull(),
|
||||
token: text("token").notNull(),
|
||||
expires: integer("expires", { mode: "timestamp_ms" }).notNull()
|
||||
}, (vt) => ({
|
||||
nameDoesntMatter: primaryKey(vt.identifier, vt.token)
|
||||
}))
|
||||
export const verificationTokens = sqliteTable(
|
||||
"verificationToken",
|
||||
{
|
||||
identifier: text("identifier").notNull(),
|
||||
token: text("token").notNull(),
|
||||
expires: integer("expires", { mode: "timestamp_ms" }).notNull(),
|
||||
},
|
||||
(vt) => ({
|
||||
nameDoesntMatter: primaryKey(vt.identifier, vt.token),
|
||||
})
|
||||
)
|
||||
|
||||
export const db = drizzle(sqlite);
|
||||
export const db = drizzle(sqlite)
|
||||
|
||||
export type Thing = typeof db
|
||||
export type DrizzleClient = typeof db
|
||||
|
||||
migrate(db, { migrationsFolder: "./drizzle" })
|
||||
migrate(db, { migrationsFolder: "./drizzle" })
|
||||
|
||||
Reference in New Issue
Block a user