Files

45 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

// Verify the Better Auth ↔ Prisma schema by performing a real signup.
// Run: npx tsx scripts/test-auth.ts
import "dotenv/config";
import { auth } from "@/lib/auth/auth";
import { prisma } from "@/lib/db";
async function main() {
const email = `verify_${Date.now()}@podcastdistributionai.test`;
try {
await auth.api.signUpEmail({
body: { email, password: "Password123!", name: "Verify User" },
});
console.log("signUpEmail: completed");
} catch (e) {
// The nextCookies plugin may throw when run outside a Next request — the DB
// write happens first, so we still verify via the row below.
console.log("signUpEmail threw (often just the cookie step):", (e as Error).message);
}
const user = await prisma.user.findUnique({
where: { email },
include: { accounts: true, sessions: true },
});
if (user) {
console.log(
`✓ Better Auth schema works — user=${user.email} role=${user.role} ` +
`accounts=${user.accounts.length} (provider=${user.accounts[0]?.providerId}) ` +
`hasPassword=${!!user.accounts[0]?.password}`
);
// Clean up the test user.
await prisma.user.delete({ where: { id: user.id } });
console.log("✓ test user cleaned up");
} else {
console.log("✗ No user row created — schema mismatch likely");
}
}
main()
.catch((e) => {
console.error("Failed:", e.message ?? e);
process.exit(1);
})
.finally(() => prisma.$disconnect());