PouchDB 適配器
資源
設定
安裝
npm install pouchdb pouchdb-find @auth/pouchdb-adapter
組態設定
./auth.ts
import NextAuth from "next-auth"
import { PouchDBAdapter } from "@auth/pouchdb-adapter"
import PouchDB from "pouchdb"
// Setup your PouchDB instance and database
PouchDB.plugin(require("pouchdb-adapter-leveldb")) // Or any other adapter
.plugin(require("pouchdb-find")) // Don't forget the `pouchdb-find` plugin
const pouchdb = new PouchDB("auth_db", { adapter: "leveldb" })
export const { handlers, auth, signIn, signOut } = NextAuth({
providers: [],
adapter: PouchDBAdapter(pouchdb),
})
💡
根據您的架構,您可以使用 PouchDB 的 http 適配器來連線任何與 CouchDB 協定相容的資料庫(CouchDB、Cloudant 等),或使用任何其他與 PouchDB 相容的適配器(leveldb、記憶體內等)。
您的 PouchDB 實例必須提供 pouchdb-find
外掛程式,因為適配器在內部使用它來建立和管理索引
進階用法
記憶體優先快取策略
如果您需要提升身份驗證層的效能,您可以利用 PouchDB 強大的同步功能和各種適配器,來建構記憶體優先快取策略。
使用記憶體內 PouchDB 作為您的主要身份驗證資料庫,並將其與任何其他持久化的 PouchDB 同步。您可以從持久化的 PouchDB 對記憶體內 PouchDB 執行一次單向的複寫,然後進行雙向的持續同步。
由於並發、函數啟動時間增加等各種原因,這在無伺服器環境中可能不會顯著提升效能。
有關更多詳細資訊,請參閱 https://pouchdb.com/api.html#sync