migrate: replace NextAuth.js with Better Auth

- Install better-auth and @better-auth/drizzle-adapter
- Create src/lib/auth.ts with Better Auth configuration using bcrypt
- Update database schema: change auth table IDs from uuid to text
- Update route handler from /api/auth/[...nextauth] to /api/auth/[...all]
- Update tRPC context and middleware for Better Auth session handling
- Update client components to use Better Auth APIs (signIn, signOut)
- Update seed script with text-based IDs and correct account schema
- Fix type errors in wizard components (robotId, optional chaining)
- Fix API paths: api.robots.initialize -> api.robots.plugins.initialize
- Update auth router to use text IDs for Better Auth compatibility

Note: Auth tables were reset - users will need to re-register.
This commit is contained in:
Sean O'Connor
2026-03-21 23:03:55 -04:00
parent 4bed537943
commit 20d6d3de1a
37 changed files with 460 additions and 1182 deletions

View File

@@ -1,4 +1,5 @@
import Link from "next/link";
import { headers } from "next/headers";
import { Button } from "~/components/ui/button";
import {
Card,
@@ -7,10 +8,12 @@ import {
CardHeader,
CardTitle,
} from "~/components/ui/card";
import { auth } from "~/server/auth";
import { auth } from "~/lib/auth";
export default async function UnauthorizedPage() {
const session = await auth();
const session = await auth.api.getSession({
headers: await headers(),
});
return (
<div className="flex min-h-screen items-center justify-center bg-gradient-to-br from-slate-50 to-slate-100 px-4">
@@ -60,13 +63,6 @@ export default async function UnauthorizedPage() {
<div className="rounded-md bg-blue-50 p-3 text-sm text-blue-700">
<p className="font-medium">Current User:</p>
<p>{session.user.name ?? session.user.email}</p>
{session.user.roles && session.user.roles.length > 0 ? (
<p className="mt-1">
Roles: {session.user.roles.map((r) => r.role).join(", ")}
</p>
) : (
<p className="mt-1">No roles assigned</p>
)}
</div>
)}