feat: prisma fix
This commit is contained in:
parent
91b0c04208
commit
a637ab23e7
|
@ -1,8 +1,6 @@
|
|||
import type { NextApiRequest, NextApiResponse } from 'next'
|
||||
|
||||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
import prisma from '@lib/prisma';
|
||||
|
||||
interface IBody {
|
||||
key: string
|
||||
|
|
|
@ -7,17 +7,21 @@ export default function play() {
|
|||
const [grade, setGrade] = useState<number>(0);
|
||||
const router = useRouter();
|
||||
let voted;
|
||||
let password: string | null;
|
||||
const [password, setPassword] = useState<string | null>('');
|
||||
useEffect(() => {
|
||||
password = localStorage.getItem('@password');
|
||||
const pass = localStorage.getItem('@password');
|
||||
setPassword(pass);
|
||||
voted = localStorage.getItem('@voted');
|
||||
if (!password) {
|
||||
if (!pass) {
|
||||
router.push('/');
|
||||
}
|
||||
}, []);
|
||||
|
||||
async function handleSubmit(event: React.FormEvent<HTMLFormElement>) {
|
||||
event.preventDefault();
|
||||
|
||||
console.log(grade, password);
|
||||
|
||||
const response = await fetch('/api/grade', {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prismaClientSingleton = () => {
|
||||
return new PrismaClient()
|
||||
}
|
||||
|
||||
declare global {
|
||||
var prisma: undefined | ReturnType<typeof prismaClientSingleton>
|
||||
}
|
||||
|
||||
const prisma = globalThis.prisma ?? prismaClientSingleton()
|
||||
|
||||
export default prisma
|
||||
|
||||
if (process.env.NODE_ENV !== 'production') globalThis.prisma = prisma
|
|
@ -21,6 +21,7 @@
|
|||
"paths": {
|
||||
"@/*": ["./*"],
|
||||
"@components/*": ["./components/*"],
|
||||
"@lib/*": ["./lib/*"],
|
||||
}
|
||||
},
|
||||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||
|
|
Loading…
Reference in New Issue