Remult Adapter
Resources
Setup
Installation
npm install remult @auth/remult-adapter
Adapter Setup
./auth.ts
import NextAuth from "next-auth"
import { RemultAdapter } from "@auth/remult-adapter"
const { adapter, entities } = RemultAdapter()
export const { handlers, auth, signIn, signOut } = NextAuth({
adapter,
providers: [],
})
Using your own Entities
If you want to add some fields in some entities, you can override default ones.
./src/auth.ts
import { SvelteKitAuth } from "@auth/sveltekit"
import { RemultAdapter } from "@auth/remult-adapter"
import { User } from "../src/entities"
export class AppUser extends User {
@Fields.string()
jobTitle = ""
}
const { adapter, entities } = RemultAdapter({
customEntities: {
User: AppUser,
// Account: ...
// Session: ...
// Authenticator: ...
},
})
export const { handle, signIn, signOut } = SvelteKitAuth({
adapter,
providers: [],
})
Entities Setup
Import your auth entities
exported from RemultAdapter
in your remult server.
This will then allow you to use each remult DataProvider Postgres
, MySQL
, MongoDB
,
SQLite
, Microsoft SQL Server
, Oracle
, JSON Files
,
and even InMemory
(really nice for testing).
(You are missing something, join remult and add yours.)
src/routes/api/[...remult]/+server.ts
import { remultSveltekit } from "remult/remult-sveltekit"
import { Task } from "../../../shared/Task"
import { entities } from "../../../src/auth"
export const _api = remultSveltekit({
entities: [Task, ...entities],
})
Nothing about migrations ? No, it will be done the remult way, automatically 🎉. read more here
Init remult before Auth
Don’t import the handleAuth
directly and add a remult hook before.
src/hooks.server.ts
import { sequence } from "@sveltejs/kit/hooks"
import { handle as handleAuth } from "./auth"
import type { Handle } from "@sveltejs/kit"
import { _api } from "./routes/api/[...remult]/+server"
const handleRemult: Handle = async ({ event, resolve }) => {
return await _api.withRemult(event, async () => {
return resolve(event)
})
}
export const handle = sequence(handleRemult, handleAuth)