diff --git a/package-lock.json b/package-lock.json index ec912ac..df5370c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -10,9 +10,11 @@ "hasInstallScript": true, "dependencies": { "@prisma/client": "^5.14.0", - "@vercel/postgres": "^0.8.0", + "@supabase/ssr": "^0.4.0", + "@supabase/supabase-js": "^2.44.2", + "@vercel/analytics": "^1.3.1", + "@vercel/postgres": "^0.8.0", "next": "14.2.3", - "next-auth": "^4.24.7", "react": "^18", "react-dom": "^18", "zustand": "^4.5.4" @@ -1501,15 +1503,6 @@ "node": ">= 8" } }, - "node_modules/@panva/hkdf": { - "version": "1.2.0", - "resolved": "https://registry.npmjs.org/@panva/hkdf/-/hkdf-1.2.0.tgz", - "integrity": "sha512-97ZQvZJ4gJhi24Io6zI+W7B67I82q1I8i3BSzQ4OyZj1z4OW87/ruF26lrMES58inTKLy2KgVIDcx8PU4AaANQ==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, "node_modules/@pkgjs/parseargs": { "version": "0.11.0", "dev": true, @@ -2854,15 +2847,6 @@ "dev": true, "license": "MIT" }, - "node_modules/cookie": { - "version": "0.5.0", - "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.5.0.tgz", - "integrity": "sha512-YZ3GUyn/o8gfKJlnlX7g7xq4gyO6OSuhGPKaaGssGB2qgDUS0gPgtTvoyZLTt9Ab6dC4hfc9dV5arkvc/OCmrw==", - "license": "MIT", - "engines": { - "node": ">= 0.6" - } - }, "node_modules/create-jest": { "version": "29.7.0", "resolved": "https://registry.npmjs.org/create-jest/-/create-jest-29.7.0.tgz", @@ -5477,15 +5461,6 @@ "jiti": "bin/jiti.js" } }, - "node_modules/jose": { - "version": "4.15.7", - "resolved": "https://registry.npmjs.org/jose/-/jose-4.15.7.tgz", - "integrity": "sha512-L7ioP+JAuZe8v+T5+zVI9Tx8LtU8BL7NxkyDFVMv+Qr3JW0jSoYDedLtodaXwfqMpeCyx4WXFNyu9tJt4WvC1A==", - "license": "MIT", - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, "node_modules/js-tokens": { "version": "4.0.0", "license": "MIT" @@ -5841,34 +5816,6 @@ } } }, - "node_modules/next-auth": { - "version": "4.24.7", - "resolved": "https://registry.npmjs.org/next-auth/-/next-auth-4.24.7.tgz", - "integrity": "sha512-iChjE8ov/1K/z98gdKbn2Jw+2vLgJtVV39X+rCP5SGnVQuco7QOr19FRNGMIrD8d3LYhHWV9j9sKLzq1aDWWQQ==", - "license": "ISC", - "dependencies": { - "@babel/runtime": "^7.20.13", - "@panva/hkdf": "^1.0.2", - "cookie": "^0.5.0", - "jose": "^4.15.5", - "oauth": "^0.9.15", - "openid-client": "^5.4.0", - "preact": "^10.6.3", - "preact-render-to-string": "^5.1.19", - "uuid": "^8.3.2" - }, - "peerDependencies": { - "next": "^12.2.5 || ^13 || ^14", - "nodemailer": "^6.6.5", - "react": "^17.0.2 || ^18", - "react-dom": "^17.0.2 || ^18" - }, - "peerDependenciesMeta": { - "nodemailer": { - "optional": true - } - } - }, "node_modules/next/node_modules/postcss": { "version": "8.4.31", "funding": [ @@ -5939,12 +5886,6 @@ "node": ">=8" } }, - "node_modules/oauth": { - "version": "0.9.15", - "resolved": "https://registry.npmjs.org/oauth/-/oauth-0.9.15.tgz", - "integrity": "sha512-a5ERWK1kh38ExDEfoO6qUHJb32rd7aYmPHuyCu3Fta/cnICvYmgd2uhuKXvPD+PXB+gCEYYEaQdIRAjCOwAKNA==", - "license": "MIT" - }, "node_modules/object-assign": { "version": "4.1.1", "dev": true, @@ -6069,15 +6010,6 @@ "url": "https://github.com/sponsors/ljharb" } }, - "node_modules/oidc-token-hash": { - "version": "5.0.3", - "resolved": "https://registry.npmjs.org/oidc-token-hash/-/oidc-token-hash-5.0.3.tgz", - "integrity": "sha512-IF4PcGgzAr6XXSff26Sk/+P4KZFJVuHAJZj3wgO3vX2bMdNVp/QXTP3P7CEm9V1IdG8lDLY3HhiqpsE/nOwpPw==", - "license": "MIT", - "engines": { - "node": "^10.13.0 || >=12.0.0" - } - }, "node_modules/once": { "version": "1.4.0", "dev": true, @@ -6102,48 +6034,6 @@ "url": "https://github.com/sponsors/sindresorhus" } }, - "node_modules/openid-client": { - "version": "5.6.5", - "resolved": "https://registry.npmjs.org/openid-client/-/openid-client-5.6.5.tgz", - "integrity": "sha512-5P4qO9nGJzB5PI0LFlhj4Dzg3m4odt0qsJTfyEtZyOlkgpILwEioOhVVJOrS1iVH494S4Ee5OCjjg6Bf5WOj3w==", - "license": "MIT", - "dependencies": { - "jose": "^4.15.5", - "lru-cache": "^6.0.0", - "object-hash": "^2.2.0", - "oidc-token-hash": "^5.0.3" - }, - "funding": { - "url": "https://github.com/sponsors/panva" - } - }, - "node_modules/openid-client/node_modules/lru-cache": { - "version": "6.0.0", - "resolved": "https://registry.npmjs.org/lru-cache/-/lru-cache-6.0.0.tgz", - "integrity": "sha512-Jo6dJ04CmSjuznwJSS3pUeWmd/H0ffTlkXXgwZi+eq1UCmqQwCh+eLsYOYCwY991i2Fah4h1BEMCx4qThGbsiA==", - "license": "ISC", - "dependencies": { - "yallist": "^4.0.0" - }, - "engines": { - "node": ">=10" - } - }, - "node_modules/openid-client/node_modules/object-hash": { - "version": "2.2.0", - "resolved": "https://registry.npmjs.org/object-hash/-/object-hash-2.2.0.tgz", - "integrity": "sha512-gScRMn0bS5fH+IuwyIFgnh9zBdo4DV+6GhygmWM9HyNJSgS0hScp1f5vjtm7oIIOiT9trXrShAkLFSc2IqKNgw==", - "license": "MIT", - "engines": { - "node": ">= 6" - } - }, - "node_modules/openid-client/node_modules/yallist": { - "version": "4.0.0", - "resolved": "https://registry.npmjs.org/yallist/-/yallist-4.0.0.tgz", - "integrity": "sha512-3wdGidZyq5PB084XLES5TpOSRA3wjXAlIWMhum2kRcv/41Sn2emQ0dycQW4uZXLejwKvg6EsvbdlVL+FYEct7A==", - "license": "ISC" - }, "node_modules/optionator": { "version": "0.9.4", "dev": true, @@ -6585,34 +6475,6 @@ "node": ">=0.10.0" } }, - "node_modules/preact": { - "version": "10.22.1", - "resolved": "https://registry.npmjs.org/preact/-/preact-10.22.1.tgz", - "integrity": "sha512-jRYbDDgMpIb5LHq3hkI0bbl+l/TQ9UnkdQ0ww+lp+4MMOdqaUYdFc5qeyP+IV8FAd/2Em7drVPeKdQxsiWCf/A==", - "license": "MIT", - "funding": { - "type": "opencollective", - "url": "https://opencollective.com/preact" - } - }, - "node_modules/preact-render-to-string": { - "version": "5.2.6", - "resolved": "https://registry.npmjs.org/preact-render-to-string/-/preact-render-to-string-5.2.6.tgz", - "integrity": "sha512-JyhErpYOvBV1hEPwIxc/fHWXPfnEGdRKxc8gFdAZ7XV4tlzyzG847XAyEZqoDnynP88akM4eaHcSOzNcLWFguw==", - "license": "MIT", - "dependencies": { - "pretty-format": "^3.8.0" - }, - "peerDependencies": { - "preact": ">=10" - } - }, - "node_modules/preact-render-to-string/node_modules/pretty-format": { - "version": "3.8.0", - "resolved": "https://registry.npmjs.org/pretty-format/-/pretty-format-3.8.0.tgz", - "integrity": "sha512-WuxUnVtlWL1OfZFQFuqvnvs6MiAGk9UNsBostyBOB0Is9wb5uRESevA6rnl/rkksXaGX3GzZhPup5d6Vp1nFew==", - "license": "MIT" - }, "node_modules/prelude-ls": { "version": "1.2.1", "dev": true, @@ -7804,15 +7666,6 @@ "dev": true, "license": "MIT" }, - "node_modules/uuid": { - "version": "8.3.2", - "resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz", - "integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==", - "license": "MIT", - "bin": { - "uuid": "dist/bin/uuid" - } - }, "node_modules/v8-to-istanbul": { "version": "9.3.0", "resolved": "https://registry.npmjs.org/v8-to-istanbul/-/v8-to-istanbul-9.3.0.tgz", diff --git a/package.json b/package.json index 7ccdad4..a9da6fc 100644 --- a/package.json +++ b/package.json @@ -17,7 +17,6 @@ "@vercel/analytics": "^1.3.1", "@vercel/postgres": "^0.8.0", "next": "14.2.3", - "next-auth": "^4.24.7", "react": "^18", "react-dom": "^18", "zustand": "^4.5.4" diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 77ceb94..6f093ff 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -1,57 +1,46 @@ -// This is your Prisma schema file, -// learn more about it in the docs: https://pris.ly/d/prisma-schema - -// Looking for ways to speed up your queries, or scale easily with your serverless or edge functions? -// Try Prisma Accelerate: https://pris.ly/cli/accelerate-init - generator client { provider = "prisma-client-js" } + datasource db { - provider = "postgresql" - url=env("DATABASE_URL") + provider = "postgresql" + url = env("DATABASE_URL") directUrl = env("DIRECT_URL") } - - // url = env("POSTGRES_PRISMA_URL") // uses connection pooling - // directUrl = env("POSTGRES_URL_NON_POOLING") // uses a direct connection model FeedBack { - id Int @id @default(autoincrement()) - feedback String - vote Int @default(0) + id Int @id @default(autoincrement()) + feedback String + vote Int @default(0) } -enum Provider{ - GOOGLE - EMAIL - KAKAO -} model User { - id Int @id @default(autoincrement()) - username String - provider Provider - email String? @unique - profile_Image String? @unique - createdAt DateTime @default(now()) - access_token String? - refresh_token String? - upLoaded_Posts Quote[] @relation("Upload") - liked_Posts Quote[] @relation("Completed") - completedPosts Quote[] @relation("Liked") + id Int @id @default(autoincrement()) + username String + provider String? + email String? @unique + profile_Image String? @unique + auth_id String @unique + upLoaded_Posts Quote[] @relation("Upload") + Quote_Quote_completed_UserIdToUser Quote[] @relation("Quote_completed_UserIdToUser") + Quote_Quote_liked_userIdToUser Quote[] @relation("Quote_liked_userIdToUser") +} + +model Quote { + id Int @id @default(autoincrement()) + upload_userId Int + author String + content String + createdAt DateTime @default(now()) + private Boolean? + view Int @default(0) + upload_User User @relation("Upload", fields: [upload_userId], references: [id]) + User_Quote_completed_UserIdToUser User[] @relation("Quote_completed_UserIdToUser") + User_Quote_liked_userIdToUser User[] @relation("Quote_liked_userIdToUser") } -model Quote{ - id Int @id - upload_User User @relation("Upload",fields: [upload_userId], references: [id]) - completed_User User[] @relation("Completed") - liked_User User[] @relation("Liked") - upload_userId Int - completed_UserId Int - liked_userId Int - author String - content String - createdAt DateTime @default(now()) - private Boolean - view Int @default(0) +enum Provider { + GOOGLE + EMAIL + KAKAO } diff --git a/src/app/api/auth/[...nextauth]/route.ts b/src/app/api/auth/[...nextauth]/route.ts deleted file mode 100644 index e04eadd..0000000 --- a/src/app/api/auth/[...nextauth]/route.ts +++ /dev/null @@ -1,43 +0,0 @@ -// import NextAuth from "next-auth"; -// import Email from "next-auth/providers/email"; -// import GoogleProvider from "next-auth/providers/google"; -// import Kakao from "next-auth/providers/kakao"; - -// const handler = NextAuth({ -// providers: [ -// GoogleProvider({ -// clientId: process.env.GOOGLE_CLIENT_ID_DEV as string, -// clientSecret: process.env.GOOGLE_CLIENT_SECRET_DEV as string, -// }), -// // Kakao({}) -// // Email({ -// // }) -// ], -// callbacks: { -// async signIn({ user, account, profile, email, credentials }) { -// const isAllowedToSignIn = true; -// if (isAllowedToSignIn) { -// return "/"; -// } else { -// // Return false to display a default error message -// return "/"; -// // Or you can return a URL to redirect to: -// // return '/unauthorized' -// } -// }, -// async redirect({ url, baseUrl }) { -// return baseUrl; -// }, -// async session({ session, user, token }) { -// return session; -// }, -// async jwt({ token, user, account }) { -// if (account) { -// token.accessToken = account.access_token; -// } -// return token; -// }, -// }, -// pages: {}, -// }); -// export { handler as GET, handler as POST }; diff --git a/src/app/api/auth/confirm/route.ts b/src/app/api/auth/confirm/route.ts index c8503cb..7220b67 100644 --- a/src/app/api/auth/confirm/route.ts +++ b/src/app/api/auth/confirm/route.ts @@ -21,7 +21,6 @@ export async function GET(request: NextRequest) { redirect(next); } } - // redirect the user to an error page with some instructions redirect("/error"); } diff --git a/src/app/api/quotes/route.ts b/src/app/api/quotes/route.ts new file mode 100644 index 0000000..b19830d --- /dev/null +++ b/src/app/api/quotes/route.ts @@ -0,0 +1,27 @@ +"user server"; + +import prisma from "@/app/lib/prisma"; +import { NextRequest } from "next/server"; + +export async function GET() { + const quotes = await prisma.quote.findMany({ + orderBy: [ + { + id: "asc", + }, + ], + }); + return Response.json({ message: "success", data: quotes }, { status: 200 }); +} + +export async function POST(req: NextRequest) { + const { author, content, upload_User } = await req.json(); + const user = await prisma.quote.create({ + data: { + author: author, + content: content, + upload_User: upload_User, + }, + }); + return Response.json({ message: "success", data: user }, { status: 200 }); +} diff --git a/src/app/api/user/route.ts b/src/app/api/user/route.ts new file mode 100644 index 0000000..f34831a --- /dev/null +++ b/src/app/api/user/route.ts @@ -0,0 +1,29 @@ +"user server"; + +import prisma from "@/app/lib/prisma"; +import { NextRequest } from "next/server"; + +export async function GET(req: NextRequest) { + const { auth_id } = await req.json(); + const user = await prisma.user.findUnique({ + where: { + auth_id: auth_id, + }, + }); + return Response.json({ message: "success", data: user }, { status: 200 }); +} + +export async function POST(req: NextRequest) { + const { username, provider, email, profile_Image, auth_id } = + await req.json(); + const user = await prisma.user.create({ + data: { + username: username, + provider: provider, + email: email, + profile_Image: profile_Image, + auth_id: auth_id, + }, + }); + return Response.json({ message: "success", data: user }, { status: 200 }); +} diff --git a/src/app/component/header/page.tsx b/src/app/component/header/page.tsx index 906c69e..90f9ae3 100644 --- a/src/app/component/header/page.tsx +++ b/src/app/component/header/page.tsx @@ -20,20 +20,13 @@ export default function Header() { const supabase = createClient(); await supabase.auth.getUser().then((value) => { if (value.data.user) { - if (localStorage.getItem("userName")) { - const user = localStorage.getItem("userName") as string; - setName(user); - } else - localStorage.setItem( - "userName", - value.data.user.user_metadata.name - ); - console.log(value.data.user.user_metadata); - } else console.log(value); + setName(value.data.user.toString()); + } }); } getUserData(); }, []); + const handleSignout = () => { localStorage.removeItem("userName"); signOut(); diff --git a/src/app/login/actions.ts b/src/app/login/actions.ts index 0807cdd..68dc549 100644 --- a/src/app/login/actions.ts +++ b/src/app/login/actions.ts @@ -4,6 +4,7 @@ import { cookies } from "next/headers"; import { revalidatePath } from "next/cache"; import { redirect } from "next/navigation"; import { createClient } from "@/app/utils/supabase/server"; +import { NextRequest, NextResponse } from "next/server"; export async function googleLogin() { const supabase = createClient(); @@ -17,8 +18,6 @@ export async function googleLogin() { }, }, }); - - //Send to google Login URL if (data.url) { redirect(data.url); // use the redirect API for your server framework } @@ -26,7 +25,34 @@ export async function googleLogin() { console.log(error); redirect("/error"); } + revalidatePath("/", "layout"); + redirect("/"); +} +export async function signUpPWD(formData: FormData) { + const supabase = createClient(); + const data = { + email: formData.get("email") as string, + password: formData.get("password") as string, + }; + const { error } = await supabase.auth.signUp(data); + if (error) { + redirect("/error"); + } + revalidatePath("/", "layout"); + redirect("/"); +} +export async function signInPWD(formData: FormData) { + const supabase = createClient(); + const data = { + email: formData.get("email") as string, + password: formData.get("password") as string, + name: formData.get("name") as string, + }; + const { error } = await supabase.auth.signInWithPassword(data); + if (error) { + redirect("/error"); + } revalidatePath("/", "layout"); redirect("/"); } diff --git a/src/app/login/page.tsx b/src/app/login/page.tsx index 3d4bff6..fbfa1c2 100644 --- a/src/app/login/page.tsx +++ b/src/app/login/page.tsx @@ -1,22 +1,53 @@ "use client"; import Link from "next/link"; -import { googleLogin, signOut } from "./actions"; +import { googleLogin, signOut, signInPWD, signUpPWD } from "./actions"; import { useEffect, useState } from "react"; export default function LoginPage() { - const handleClick = () => { - googleLogin(); - }; return (