mirror of
https://github.com/soconnor0919/hristudio.git
synced 2026-03-24 03:37:51 -04:00
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:
@@ -3,7 +3,7 @@
|
||||
import React, { useEffect, useRef } from "react";
|
||||
import Link from "next/link";
|
||||
import { usePathname } from "next/navigation";
|
||||
import { signOut, useSession } from "next-auth/react";
|
||||
import { signOut, useSession } from "~/lib/auth-client";
|
||||
import { toast } from "sonner";
|
||||
import {
|
||||
BarChart3,
|
||||
@@ -203,7 +203,8 @@ export function AppSidebar({
|
||||
: [];
|
||||
|
||||
const handleSignOut = async () => {
|
||||
await signOut({ callbackUrl: "/" });
|
||||
await signOut();
|
||||
window.location.href = "/";
|
||||
};
|
||||
|
||||
const handleStudySelect = async (studyId: string) => {
|
||||
|
||||
@@ -167,7 +167,7 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
});
|
||||
|
||||
// Robot initialization mutation (for startup routine)
|
||||
const initializeRobotMutation = api.robots.initialize.useMutation({
|
||||
const initializeRobotMutation = api.robots.plugins.initialize.useMutation({
|
||||
onSuccess: () => {
|
||||
toast.success("Robot initialized", {
|
||||
description: "Autonomous Life disabled and robot awake.",
|
||||
@@ -188,7 +188,7 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
});
|
||||
|
||||
const executeSystemActionMutation =
|
||||
api.robots.executeSystemAction.useMutation();
|
||||
api.robots.plugins.executeSystemAction.useMutation();
|
||||
const [isCompleting, setIsCompleting] = useState(false);
|
||||
|
||||
// Map database step types to component step types
|
||||
@@ -579,14 +579,20 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
};
|
||||
|
||||
const handleNextStep = (targetIndex?: number) => {
|
||||
console.log(`[DEBUG] handleNextStep called: targetIndex=${targetIndex}, currentStepIndex=${currentStepIndex}`);
|
||||
console.log(`[DEBUG] Steps: ${steps.map((s, i) => `${i}:${s.name}`).join(' | ')}`);
|
||||
|
||||
console.log(
|
||||
`[DEBUG] handleNextStep called: targetIndex=${targetIndex}, currentStepIndex=${currentStepIndex}`,
|
||||
);
|
||||
console.log(
|
||||
`[DEBUG] Steps: ${steps.map((s, i) => `${i}:${s.name}`).join(" | ")}`,
|
||||
);
|
||||
|
||||
// If explicit target provided (from branching choice), use it
|
||||
if (typeof targetIndex === "number") {
|
||||
// Find step by index to ensure safety
|
||||
if (targetIndex >= 0 && targetIndex < steps.length) {
|
||||
console.log(`[WizardInterface] Manual jump to step ${targetIndex} (${steps[targetIndex]?.name})`);
|
||||
console.log(
|
||||
`[WizardInterface] Manual jump to step ${targetIndex} (${steps[targetIndex]?.name})`,
|
||||
);
|
||||
|
||||
// Log manual jump
|
||||
logEventMutation.mutate({
|
||||
@@ -613,7 +619,9 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
});
|
||||
return;
|
||||
} else {
|
||||
console.warn(`[DEBUG] Invalid targetIndex: ${targetIndex}, steps.length=${steps.length}`);
|
||||
console.warn(
|
||||
`[DEBUG] Invalid targetIndex: ${targetIndex}, steps.length=${steps.length}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -868,10 +876,14 @@ export const WizardInterface = React.memo(function WizardInterface({
|
||||
if (parameters.nextStepId) {
|
||||
const nextId = String(parameters.nextStepId);
|
||||
const targetIndex = steps.findIndex((s) => s.id === nextId);
|
||||
console.log(`[DEBUG] Branch choice: value=${parameters.value}, label=${parameters.label}`);
|
||||
console.log(
|
||||
`[DEBUG] Branch choice: value=${parameters.value}, label=${parameters.label}`,
|
||||
);
|
||||
console.log(`[DEBUG] Target step ID: ${nextId}`);
|
||||
console.log(`[DEBUG] Target index in steps array: ${targetIndex}`);
|
||||
console.log(`[DEBUG] Available step IDs: ${steps.map(s => s.id).join(', ')}`);
|
||||
console.log(
|
||||
`[DEBUG] Available step IDs: ${steps.map((s) => s.id).join(", ")}`,
|
||||
);
|
||||
if (targetIndex !== -1) {
|
||||
console.log(
|
||||
`[WizardInterface] Choice-based jump to step ${targetIndex} (${nextId})`,
|
||||
|
||||
@@ -403,8 +403,8 @@ export function WizardExecutionPanel({
|
||||
size="lg"
|
||||
onClick={
|
||||
currentStepIndex === steps.length - 1
|
||||
? onCompleteTrial
|
||||
: () => onNextStep()
|
||||
? (onCompleteTrial ?? (() => {}))
|
||||
: () => onNextStep?.()
|
||||
}
|
||||
className={`w-full max-w-sm text-white shadow-lg transition-all hover:scale-[1.02] ${
|
||||
currentStepIndex === steps.length - 1
|
||||
|
||||
Reference in New Issue
Block a user