├── .eslintrc.json ├── src ├── app │ ├── globals.css │ ├── favicon.ico │ ├── login │ │ ├── card.tsx │ │ ├── page.tsx │ │ └── form.tsx │ ├── layout.tsx │ ├── api │ │ └── auth │ │ │ └── [...nextauth] │ │ │ └── route.ts │ └── page.tsx ├── store │ └── index.ts ├── lib │ └── prisma.ts └── provider │ └── index.tsx ├── next.config.js ├── postcss.config.js ├── prisma ├── migrations │ ├── migration_lock.toml │ ├── 20230909032600_ │ │ └── migration.sql │ ├── 20230909032837_ │ │ └── migration.sql │ └── 20230909042539_ │ │ └── migration.sql └── schema.prisma ├── .gitignore ├── tailwind.config.ts ├── public ├── vercel.svg └── next.svg ├── .env ├── tsconfig.json ├── package.json └── README.md /.eslintrc.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "next/core-web-vitals" 3 | } 4 | -------------------------------------------------------------------------------- /src/app/globals.css: -------------------------------------------------------------------------------- 1 | @tailwind base; 2 | @tailwind components; 3 | @tailwind utilities; 4 | -------------------------------------------------------------------------------- /next.config.js: -------------------------------------------------------------------------------- 1 | /** @type {import('next').NextConfig} */ 2 | const nextConfig = {} 3 | 4 | module.exports = nextConfig 5 | -------------------------------------------------------------------------------- /postcss.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | plugins: { 3 | tailwindcss: {}, 4 | autoprefixer: {}, 5 | }, 6 | } 7 | -------------------------------------------------------------------------------- /src/app/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/crusherblack/tutorial-nextjs-13-ecommerce-cart-tahu-coding/HEAD/src/app/favicon.ico -------------------------------------------------------------------------------- /prisma/migrations/migration_lock.toml: -------------------------------------------------------------------------------- 1 | # Please do not edit this file manually 2 | # It should be added in your version-control system (i.e. Git) 3 | provider = "postgresql" -------------------------------------------------------------------------------- /src/app/login/card.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | 3 | function Card({ user }: { user: string | null | undefined }) { 4 | return ( 5 |
6 | welcom back {user} 7 |
8 | ); 9 | } 10 | 11 | export default Card; 12 | -------------------------------------------------------------------------------- /src/store/index.ts: -------------------------------------------------------------------------------- 1 | import { configureStore } from "@reduxjs/toolkit"; 2 | 3 | export const store = configureStore({ 4 | reducer: {}, 5 | }); 6 | 7 | // Infer the `RootState` and `AppDispatch` types from the store itself 8 | export type RootState = ReturnType; 9 | // Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} 10 | export type AppDispatch = typeof store.dispatch; 11 | -------------------------------------------------------------------------------- /src/app/login/page.tsx: -------------------------------------------------------------------------------- 1 | import { OPTIONS } from "../api/auth/[...nextauth]/route"; 2 | import Card from "./card"; 3 | import Form from "./form"; 4 | import { getServerSession } from "next-auth/next"; 5 | 6 | export default async function Home() { 7 | const session = await getServerSession(OPTIONS); 8 | return ( 9 |
10 | {session ? :
} 11 |
12 | ); 13 | } 14 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # next.js 12 | /.next/ 13 | /out/ 14 | 15 | # production 16 | /build 17 | 18 | # misc 19 | .DS_Store 20 | *.pem 21 | 22 | # debug 23 | npm-debug.log* 24 | yarn-debug.log* 25 | yarn-error.log* 26 | 27 | # local env files 28 | .env*.local 29 | 30 | # vercel 31 | .vercel 32 | 33 | # typescript 34 | *.tsbuildinfo 35 | next-env.d.ts 36 | -------------------------------------------------------------------------------- /src/lib/prisma.ts: -------------------------------------------------------------------------------- 1 | import { PrismaClient } from "@prisma/client"; 2 | 3 | // PrismaClient is attached to the `global` object in development to prevent 4 | // exhausting your database connection limit. 5 | // 6 | // Learn more: 7 | // https://pris.ly/d/help/next-js-best-practices 8 | 9 | const globalForPrisma = global as unknown as { prisma: PrismaClient }; 10 | 11 | export const prisma = globalForPrisma.prisma || new PrismaClient(); 12 | 13 | if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma; 14 | 15 | export default prisma; 16 | -------------------------------------------------------------------------------- /tailwind.config.ts: -------------------------------------------------------------------------------- 1 | import type { Config } from 'tailwindcss' 2 | 3 | const config: Config = { 4 | content: [ 5 | './src/pages/**/*.{js,ts,jsx,tsx,mdx}', 6 | './src/components/**/*.{js,ts,jsx,tsx,mdx}', 7 | './src/app/**/*.{js,ts,jsx,tsx,mdx}', 8 | ], 9 | theme: { 10 | extend: { 11 | backgroundImage: { 12 | 'gradient-radial': 'radial-gradient(var(--tw-gradient-stops))', 13 | 'gradient-conic': 14 | 'conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))', 15 | }, 16 | }, 17 | }, 18 | plugins: [], 19 | } 20 | export default config 21 | -------------------------------------------------------------------------------- /public/vercel.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.env: -------------------------------------------------------------------------------- 1 | # Environment variables declared in this file are automatically made available to Prisma. 2 | # See the documentation for more detail: https://pris.ly/d/prisma-schema#accessing-environment-variables-from-the-schema 3 | 4 | # Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB. 5 | # See the documentation for all the connection string options: https://pris.ly/d/connection-strings 6 | 7 | DATABASE_URL="postgresql://postgres:aVqyACyb2m4JCZs1@db.qbjublwgynlwktxetjpa.supabase.co:5432/postgres" 8 | NEXTAUTH_URL="http://localhost:3001" 9 | NEXTAUTH_SECRET="awdawdawd" 10 | -------------------------------------------------------------------------------- /src/provider/index.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | 3 | import { ReactNode } from "react"; 4 | 5 | import { SessionProvider } from "next-auth/react"; 6 | import { StyleProvider } from "@ant-design/cssinjs"; 7 | import { store } from "@/store"; 8 | import { Provider as ReduxProvider } from "react-redux"; 9 | 10 | type Props = { 11 | children: ReactNode; 12 | }; 13 | 14 | const Provider = ({ children }: Props) => { 15 | return ( 16 | 17 | 18 | {children} 19 | 20 | 21 | ); 22 | }; 23 | 24 | export default Provider; 25 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": ["dom", "dom.iterable", "esnext"], 5 | "allowJs": true, 6 | "skipLibCheck": true, 7 | "strict": true, 8 | "noEmit": true, 9 | "esModuleInterop": true, 10 | "module": "esnext", 11 | "moduleResolution": "bundler", 12 | "resolveJsonModule": true, 13 | "isolatedModules": true, 14 | "jsx": "preserve", 15 | "incremental": true, 16 | "plugins": [ 17 | { 18 | "name": "next" 19 | } 20 | ], 21 | "paths": { 22 | "@/*": ["./src/*"] 23 | } 24 | }, 25 | "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], 26 | "exclude": ["node_modules"] 27 | } 28 | -------------------------------------------------------------------------------- /src/app/layout.tsx: -------------------------------------------------------------------------------- 1 | import type { Metadata } from "next"; 2 | import { Inter } from "next/font/google"; 3 | 4 | import "./globals.css"; 5 | import Provider from "@/provider"; 6 | 7 | const inter = Inter({ subsets: ["latin"] }); 8 | 9 | export const metadata: Metadata = { 10 | title: "E-Commerce Tahu Coding", 11 | description: "Modern E-Commerce with latest stack", 12 | }; 13 | 14 | export default function RootLayout({ 15 | children, 16 | }: { 17 | children: React.ReactNode; 18 | }) { 19 | return ( 20 | 21 | 22 | 23 |
{children}
24 |
25 | 26 | 27 | ); 28 | } 29 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ecommerce-app", 3 | "version": "0.1.0", 4 | "private": true, 5 | "scripts": { 6 | "dev": "next dev", 7 | "build": "next build", 8 | "start": "next start", 9 | "lint": "next lint" 10 | }, 11 | "dependencies": { 12 | "@auth/prisma-adapter": "^1.0.2", 13 | "@prisma/client": "^5.2.0", 14 | "@reduxjs/toolkit": "^1.9.5", 15 | "@types/node": "20.6.0", 16 | "@types/react": "18.2.21", 17 | "@types/react-dom": "18.2.7", 18 | "antd": "^5.9.0", 19 | "autoprefixer": "10.4.15", 20 | "eslint": "8.49.0", 21 | "eslint-config-next": "13.4.19", 22 | "next": "13.4.19", 23 | "next-auth": "^4.23.1", 24 | "postcss": "8.4.29", 25 | "prisma": "^5.2.0", 26 | "react": "18.2.0", 27 | "react-dom": "18.2.0", 28 | "react-redux": "^8.1.2", 29 | "tailwindcss": "3.3.3", 30 | "typescript": "5.2.2" 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /src/app/api/auth/[...nextauth]/route.ts: -------------------------------------------------------------------------------- 1 | import type { NextAuthOptions } from "next-auth"; 2 | 3 | import NextAuth from "next-auth"; 4 | import CredentialsProvider from "next-auth/providers/credentials"; 5 | 6 | export const OPTIONS: NextAuthOptions = { 7 | providers: [ 8 | CredentialsProvider({ 9 | name: "credentials", 10 | credentials: { 11 | username: { label: "Username", type: "text", placeholder: "jsmith" }, 12 | password: { label: "Password", type: "password" }, 13 | }, 14 | async authorize(credentials) { 15 | const user = { id: "1", name: "admin", password: "admin" }; 16 | 17 | if ( 18 | credentials?.username == user.name && 19 | credentials.password == user.password 20 | ) { 21 | return user; 22 | } else { 23 | return null; 24 | } 25 | }, 26 | }), 27 | ], 28 | pages: { 29 | signIn: "/login", 30 | }, 31 | session: { 32 | strategy: "jwt", 33 | }, 34 | jwt: { 35 | secret: "adawd", 36 | }, 37 | callbacks: { 38 | async redirect({ url, baseUrl }) { 39 | return "http://localhost:3001/login"; 40 | }, 41 | }, 42 | }; 43 | 44 | const handler = NextAuth(OPTIONS); 45 | 46 | export { handler as GET, handler as POST }; 47 | -------------------------------------------------------------------------------- /public/next.svg: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app). 2 | 3 | ## Getting Started 4 | 5 | First, run the development server: 6 | 7 | ```bash 8 | npm run dev 9 | # or 10 | yarn dev 11 | # or 12 | pnpm dev 13 | ``` 14 | 15 | Open [http://localhost:3000](http://localhost:3000) with your browser to see the result. 16 | 17 | You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file. 18 | 19 | This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font. 20 | 21 | ## Learn More 22 | 23 | To learn more about Next.js, take a look at the following resources: 24 | 25 | - [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API. 26 | - [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial. 27 | 28 | You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome! 29 | 30 | ## Deploy on Vercel 31 | 32 | The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js. 33 | 34 | Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details. 35 | -------------------------------------------------------------------------------- /src/app/login/form.tsx: -------------------------------------------------------------------------------- 1 | "use client"; 2 | import React, { FormEvent, useState } from "react"; 3 | import { signIn } from "next-auth/react"; 4 | 5 | function Form() { 6 | const [name, setName] = useState(); 7 | const [password, setPassword] = useState(); 8 | function handleSubmit(e: FormEvent) { 9 | e.preventDefault(); 10 | signIn("credentials", { 11 | username: name, 12 | password, 13 | }); 14 | } 15 | return ( 16 | 20 |
21 |

You must be sign in to join

22 | we are A Team that guides Each other 23 |
24 |
25 |
26 | 27 | Or 28 | 29 |
30 |
31 |
32 | 33 | setName(e.target.value)} 35 | value={name} 36 | type="text" 37 | className="p-3 border border-slate-700 rounded-lg" 38 | id="name" 39 | placeholder="Uname@mail.com" 40 | required 41 | /> 42 |
43 |
44 | 45 | setPassword(e.target.value)} 47 | value={password} 48 | type="password" 49 | id="password" 50 | className="p-3 border border-slate-700 rounded-lg" 51 | placeholder="Password" 52 | required 53 | /> 54 |
55 |
56 | 62 | 63 | ); 64 | } 65 | 66 | export default Form; 67 | -------------------------------------------------------------------------------- /prisma/schema.prisma: -------------------------------------------------------------------------------- 1 | // This is your Prisma schema file, 2 | // learn more about it in the docs: https://pris.ly/d/prisma-schema 3 | 4 | generator client { 5 | provider = "prisma-client-js" 6 | } 7 | 8 | datasource db { 9 | provider = "postgresql" 10 | url = env("DATABASE_URL") 11 | } 12 | 13 | model User { 14 | id String @id @default(cuid()) 15 | name String? 16 | email String? @unique 17 | emailVerified DateTime? 18 | image String? 19 | role String @default("user") 20 | createdAt DateTime @default(now()) 21 | updatedAt DateTime @updatedAt 22 | Address Address[] 23 | Transaction Transaction[] 24 | 25 | @@map("users") 26 | } 27 | 28 | model Address { 29 | id String @id @default(cuid()) 30 | userId String 31 | street String 32 | city String 33 | state String 34 | country String 35 | postalCode String 36 | isDefault Int 37 | createdAt DateTime @default(now()) 38 | updatedAt DateTime? 39 | user User @relation(fields: [userId], references: [id]) 40 | transactions Transaction[] 41 | 42 | @@map("addresses") 43 | } 44 | 45 | model Transaction { 46 | id String @id @default(cuid()) 47 | transactionNumber String 48 | userId String 49 | status String @default("PENDING") 50 | totalItemsPrice Float 51 | shippingPrice Float 52 | shippingProvider String 53 | shippingType String 54 | addressId String 55 | createdAt DateTime @default(now()) 56 | updatedAt DateTime? 57 | user User @relation(fields: [userId], references: [id]) 58 | address Address @relation(fields: [addressId], references: [id]) 59 | items Item[] 60 | 61 | @@map("transactions") 62 | } 63 | 64 | model Item { 65 | id String @id @default(cuid()) 66 | productId String 67 | quantity Int 68 | transactionId String 69 | price Float 70 | createdAt DateTime @default(now()) 71 | updatedAt DateTime? 72 | product Product @relation(fields: [productId], references: [id]) 73 | transaction Transaction @relation(fields: [transactionId], references: [id]) 74 | 75 | @@map("items") 76 | } 77 | 78 | model Category { 79 | id String @id @default(cuid()) 80 | name String @unique 81 | createdAt DateTime @default(now()) 82 | updatedAt DateTime? 83 | products Product[] 84 | 85 | @@map("categories") 86 | } 87 | 88 | model Product { 89 | id String @id @default(cuid()) 90 | name String 91 | description String 92 | price Float 93 | categoryId String 94 | image String 95 | createdAt DateTime @default(now()) 96 | updatedAt DateTime? 97 | category Category @relation(fields: [categoryId], references: [id]) 98 | Item Item[] 99 | 100 | @@map("products") 101 | } 102 | -------------------------------------------------------------------------------- /prisma/migrations/20230909032600_/migration.sql: -------------------------------------------------------------------------------- 1 | -- CreateTable 2 | CREATE TABLE "Account" ( 3 | "id" TEXT NOT NULL, 4 | "userId" TEXT NOT NULL, 5 | "type" TEXT NOT NULL, 6 | "provider" TEXT NOT NULL, 7 | "providerAccountId" TEXT NOT NULL, 8 | "refresh_token" TEXT, 9 | "access_token" TEXT, 10 | "expires_at" INTEGER, 11 | "token_type" TEXT, 12 | "scope" TEXT, 13 | "id_token" TEXT, 14 | "session_state" TEXT, 15 | 16 | CONSTRAINT "Account_pkey" PRIMARY KEY ("id") 17 | ); 18 | 19 | -- CreateTable 20 | CREATE TABLE "Session" ( 21 | "id" TEXT NOT NULL, 22 | "sessionToken" TEXT NOT NULL, 23 | "userId" TEXT NOT NULL, 24 | "expires" TIMESTAMP(3) NOT NULL, 25 | 26 | CONSTRAINT "Session_pkey" PRIMARY KEY ("id") 27 | ); 28 | 29 | -- CreateTable 30 | CREATE TABLE "users" ( 31 | "id" TEXT NOT NULL, 32 | "name" TEXT, 33 | "email" TEXT, 34 | "emailVerified" TIMESTAMP(3), 35 | "image" TEXT, 36 | "role" TEXT NOT NULL DEFAULT 'user', 37 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 38 | "updatedAt" TIMESTAMP(3) NOT NULL, 39 | 40 | CONSTRAINT "users_pkey" PRIMARY KEY ("id") 41 | ); 42 | 43 | -- CreateTable 44 | CREATE TABLE "VerificationToken" ( 45 | "identifier" TEXT NOT NULL, 46 | "token" TEXT NOT NULL, 47 | "expires" TIMESTAMP(3) NOT NULL 48 | ); 49 | 50 | -- CreateTable 51 | CREATE TABLE "addresses" ( 52 | "id" TEXT NOT NULL, 53 | "userId" TEXT NOT NULL, 54 | "street" TEXT NOT NULL, 55 | "city" TEXT NOT NULL, 56 | "state" TEXT NOT NULL, 57 | "country" TEXT NOT NULL, 58 | "postalCode" TEXT NOT NULL, 59 | "isDefault" INTEGER NOT NULL, 60 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 61 | "updatedAt" TIMESTAMP(3), 62 | 63 | CONSTRAINT "addresses_pkey" PRIMARY KEY ("id") 64 | ); 65 | 66 | -- CreateTable 67 | CREATE TABLE "transactions" ( 68 | "id" TEXT NOT NULL, 69 | "transactioNumber" TEXT NOT NULL, 70 | "userId" TEXT NOT NULL, 71 | "status" TEXT NOT NULL DEFAULT 'PENDING', 72 | "totalItemsPrice" DOUBLE PRECISION NOT NULL, 73 | "shippingPrice" DOUBLE PRECISION NOT NULL, 74 | "shippingProvider" TEXT NOT NULL, 75 | "shippingType" TEXT NOT NULL, 76 | "addressId" TEXT NOT NULL, 77 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 78 | "updatedAt" TIMESTAMP(3), 79 | 80 | CONSTRAINT "transactions_pkey" PRIMARY KEY ("id") 81 | ); 82 | 83 | -- CreateTable 84 | CREATE TABLE "items" ( 85 | "id" TEXT NOT NULL, 86 | "productId" TEXT NOT NULL, 87 | "quantity" INTEGER NOT NULL, 88 | "transactionId" TEXT NOT NULL, 89 | "price" DOUBLE PRECISION NOT NULL, 90 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 91 | "updatedAt" TIMESTAMP(3), 92 | 93 | CONSTRAINT "items_pkey" PRIMARY KEY ("id") 94 | ); 95 | 96 | -- CreateTable 97 | CREATE TABLE "categories" ( 98 | "id" TEXT NOT NULL, 99 | "name" TEXT NOT NULL, 100 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 101 | "updatedAt" TIMESTAMP(3), 102 | 103 | CONSTRAINT "categories_pkey" PRIMARY KEY ("id") 104 | ); 105 | 106 | -- CreateTable 107 | CREATE TABLE "products" ( 108 | "id" TEXT NOT NULL, 109 | "name" TEXT NOT NULL, 110 | "description" TEXT NOT NULL, 111 | "price" DOUBLE PRECISION NOT NULL, 112 | "categoryId" TEXT NOT NULL, 113 | "image" TEXT NOT NULL, 114 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 115 | "updatedAt" TIMESTAMP(3), 116 | 117 | CONSTRAINT "products_pkey" PRIMARY KEY ("id") 118 | ); 119 | 120 | -- CreateIndex 121 | CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); 122 | 123 | -- CreateIndex 124 | CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); 125 | 126 | -- CreateIndex 127 | CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); 128 | 129 | -- CreateIndex 130 | CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); 131 | 132 | -- CreateIndex 133 | CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); 134 | 135 | -- CreateIndex 136 | CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name"); 137 | 138 | -- AddForeignKey 139 | ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; 140 | 141 | -- AddForeignKey 142 | ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE CASCADE ON UPDATE CASCADE; 143 | 144 | -- AddForeignKey 145 | ALTER TABLE "addresses" ADD CONSTRAINT "addresses_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 146 | 147 | -- AddForeignKey 148 | ALTER TABLE "transactions" ADD CONSTRAINT "transactions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 149 | 150 | -- AddForeignKey 151 | ALTER TABLE "transactions" ADD CONSTRAINT "transactions_addressId_fkey" FOREIGN KEY ("addressId") REFERENCES "addresses"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 152 | 153 | -- AddForeignKey 154 | ALTER TABLE "items" ADD CONSTRAINT "items_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 155 | 156 | -- AddForeignKey 157 | ALTER TABLE "items" ADD CONSTRAINT "items_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "transactions"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 158 | 159 | -- AddForeignKey 160 | ALTER TABLE "products" ADD CONSTRAINT "products_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "categories"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 161 | -------------------------------------------------------------------------------- /prisma/migrations/20230909032837_/migration.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Warnings: 3 | 4 | - You are about to drop the `addresses` table. If the table is not empty, all the data it contains will be lost. 5 | - You are about to drop the `categories` table. If the table is not empty, all the data it contains will be lost. 6 | - You are about to drop the `items` table. If the table is not empty, all the data it contains will be lost. 7 | - You are about to drop the `products` table. If the table is not empty, all the data it contains will be lost. 8 | - You are about to drop the `transactions` table. If the table is not empty, all the data it contains will be lost. 9 | - You are about to drop the `users` table. If the table is not empty, all the data it contains will be lost. 10 | 11 | */ 12 | -- DropForeignKey 13 | ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey"; 14 | 15 | -- DropForeignKey 16 | ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey"; 17 | 18 | -- DropForeignKey 19 | ALTER TABLE "addresses" DROP CONSTRAINT "addresses_userId_fkey"; 20 | 21 | -- DropForeignKey 22 | ALTER TABLE "items" DROP CONSTRAINT "items_productId_fkey"; 23 | 24 | -- DropForeignKey 25 | ALTER TABLE "items" DROP CONSTRAINT "items_transactionId_fkey"; 26 | 27 | -- DropForeignKey 28 | ALTER TABLE "products" DROP CONSTRAINT "products_categoryId_fkey"; 29 | 30 | -- DropForeignKey 31 | ALTER TABLE "transactions" DROP CONSTRAINT "transactions_addressId_fkey"; 32 | 33 | -- DropForeignKey 34 | ALTER TABLE "transactions" DROP CONSTRAINT "transactions_userId_fkey"; 35 | 36 | -- DropTable 37 | DROP TABLE "addresses"; 38 | 39 | -- DropTable 40 | DROP TABLE "categories"; 41 | 42 | -- DropTable 43 | DROP TABLE "items"; 44 | 45 | -- DropTable 46 | DROP TABLE "products"; 47 | 48 | -- DropTable 49 | DROP TABLE "transactions"; 50 | 51 | -- DropTable 52 | DROP TABLE "users"; 53 | 54 | -- CreateTable 55 | CREATE TABLE "User" ( 56 | "id" TEXT NOT NULL, 57 | "name" TEXT, 58 | "email" TEXT, 59 | "emailVerified" TIMESTAMP(3), 60 | "image" TEXT, 61 | "role" TEXT NOT NULL DEFAULT 'user', 62 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 63 | "updatedAt" TIMESTAMP(3) NOT NULL, 64 | 65 | CONSTRAINT "User_pkey" PRIMARY KEY ("id") 66 | ); 67 | 68 | -- CreateTable 69 | CREATE TABLE "Address" ( 70 | "id" TEXT NOT NULL, 71 | "userId" TEXT NOT NULL, 72 | "street" TEXT NOT NULL, 73 | "city" TEXT NOT NULL, 74 | "state" TEXT NOT NULL, 75 | "country" TEXT NOT NULL, 76 | "postalCode" TEXT NOT NULL, 77 | "isDefault" INTEGER NOT NULL, 78 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 79 | "updatedAt" TIMESTAMP(3), 80 | 81 | CONSTRAINT "Address_pkey" PRIMARY KEY ("id") 82 | ); 83 | 84 | -- CreateTable 85 | CREATE TABLE "Transaction" ( 86 | "id" TEXT NOT NULL, 87 | "transactionNumber" TEXT NOT NULL, 88 | "userId" TEXT NOT NULL, 89 | "status" TEXT NOT NULL DEFAULT 'PENDING', 90 | "totalItemsPrice" DOUBLE PRECISION NOT NULL, 91 | "shippingPrice" DOUBLE PRECISION NOT NULL, 92 | "shippingProvider" TEXT NOT NULL, 93 | "shippingType" TEXT NOT NULL, 94 | "addressId" TEXT NOT NULL, 95 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 96 | "updatedAt" TIMESTAMP(3), 97 | 98 | CONSTRAINT "Transaction_pkey" PRIMARY KEY ("id") 99 | ); 100 | 101 | -- CreateTable 102 | CREATE TABLE "Item" ( 103 | "id" TEXT NOT NULL, 104 | "productId" TEXT NOT NULL, 105 | "quantity" INTEGER NOT NULL, 106 | "transactionId" TEXT NOT NULL, 107 | "price" DOUBLE PRECISION NOT NULL, 108 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 109 | "updatedAt" TIMESTAMP(3), 110 | 111 | CONSTRAINT "Item_pkey" PRIMARY KEY ("id") 112 | ); 113 | 114 | -- CreateTable 115 | CREATE TABLE "Category" ( 116 | "id" TEXT NOT NULL, 117 | "name" TEXT NOT NULL, 118 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 119 | "updatedAt" TIMESTAMP(3), 120 | 121 | CONSTRAINT "Category_pkey" PRIMARY KEY ("id") 122 | ); 123 | 124 | -- CreateTable 125 | CREATE TABLE "Product" ( 126 | "id" TEXT NOT NULL, 127 | "name" TEXT NOT NULL, 128 | "description" TEXT NOT NULL, 129 | "price" DOUBLE PRECISION NOT NULL, 130 | "categoryId" TEXT NOT NULL, 131 | "image" TEXT NOT NULL, 132 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 133 | "updatedAt" TIMESTAMP(3), 134 | 135 | CONSTRAINT "Product_pkey" PRIMARY KEY ("id") 136 | ); 137 | 138 | -- CreateIndex 139 | CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); 140 | 141 | -- CreateIndex 142 | CREATE UNIQUE INDEX "Category_name_key" ON "Category"("name"); 143 | 144 | -- AddForeignKey 145 | ALTER TABLE "Account" ADD CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; 146 | 147 | -- AddForeignKey 148 | ALTER TABLE "Session" ADD CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE CASCADE ON UPDATE CASCADE; 149 | 150 | -- AddForeignKey 151 | ALTER TABLE "Address" ADD CONSTRAINT "Address_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 152 | 153 | -- AddForeignKey 154 | ALTER TABLE "Transaction" ADD CONSTRAINT "Transaction_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 155 | 156 | -- AddForeignKey 157 | ALTER TABLE "Transaction" ADD CONSTRAINT "Transaction_addressId_fkey" FOREIGN KEY ("addressId") REFERENCES "Address"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 158 | 159 | -- AddForeignKey 160 | ALTER TABLE "Item" ADD CONSTRAINT "Item_productId_fkey" FOREIGN KEY ("productId") REFERENCES "Product"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 161 | 162 | -- AddForeignKey 163 | ALTER TABLE "Item" ADD CONSTRAINT "Item_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "Transaction"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 164 | 165 | -- AddForeignKey 166 | ALTER TABLE "Product" ADD CONSTRAINT "Product_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "Category"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 167 | -------------------------------------------------------------------------------- /src/app/page.tsx: -------------------------------------------------------------------------------- 1 | import Image from 'next/image' 2 | 3 | export default function Home() { 4 | return ( 5 |
6 |
7 |

8 | Get started by editing  9 | src/app/page.tsx 10 |

11 | 29 |
30 | 31 |
32 | Next.js Logo 40 |
41 | 42 |
43 | 49 |

50 | Docs{' '} 51 | 52 | -> 53 | 54 |

55 |

56 | Find in-depth information about Next.js features and API. 57 |

58 |
59 | 60 | 66 |

67 | Learn{' '} 68 | 69 | -> 70 | 71 |

72 |

73 | Learn about Next.js in an interactive course with quizzes! 74 |

75 |
76 | 77 | 83 |

84 | Templates{' '} 85 | 86 | -> 87 | 88 |

89 |

90 | Explore the Next.js 13 playground. 91 |

92 |
93 | 94 | 100 |

101 | Deploy{' '} 102 | 103 | -> 104 | 105 |

106 |

107 | Instantly deploy your Next.js site to a shareable URL with Vercel. 108 |

109 |
110 |
111 |
112 | ) 113 | } 114 | -------------------------------------------------------------------------------- /prisma/migrations/20230909042539_/migration.sql: -------------------------------------------------------------------------------- 1 | /* 2 | Warnings: 3 | 4 | - You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost. 5 | - You are about to drop the `Address` table. If the table is not empty, all the data it contains will be lost. 6 | - You are about to drop the `Category` table. If the table is not empty, all the data it contains will be lost. 7 | - You are about to drop the `Item` table. If the table is not empty, all the data it contains will be lost. 8 | - You are about to drop the `Product` table. If the table is not empty, all the data it contains will be lost. 9 | - You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost. 10 | - You are about to drop the `Transaction` table. If the table is not empty, all the data it contains will be lost. 11 | - You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost. 12 | - You are about to drop the `VerificationToken` table. If the table is not empty, all the data it contains will be lost. 13 | 14 | */ 15 | -- DropForeignKey 16 | ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey"; 17 | 18 | -- DropForeignKey 19 | ALTER TABLE "Address" DROP CONSTRAINT "Address_userId_fkey"; 20 | 21 | -- DropForeignKey 22 | ALTER TABLE "Item" DROP CONSTRAINT "Item_productId_fkey"; 23 | 24 | -- DropForeignKey 25 | ALTER TABLE "Item" DROP CONSTRAINT "Item_transactionId_fkey"; 26 | 27 | -- DropForeignKey 28 | ALTER TABLE "Product" DROP CONSTRAINT "Product_categoryId_fkey"; 29 | 30 | -- DropForeignKey 31 | ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey"; 32 | 33 | -- DropForeignKey 34 | ALTER TABLE "Transaction" DROP CONSTRAINT "Transaction_addressId_fkey"; 35 | 36 | -- DropForeignKey 37 | ALTER TABLE "Transaction" DROP CONSTRAINT "Transaction_userId_fkey"; 38 | 39 | -- DropTable 40 | DROP TABLE "Account"; 41 | 42 | -- DropTable 43 | DROP TABLE "Address"; 44 | 45 | -- DropTable 46 | DROP TABLE "Category"; 47 | 48 | -- DropTable 49 | DROP TABLE "Item"; 50 | 51 | -- DropTable 52 | DROP TABLE "Product"; 53 | 54 | -- DropTable 55 | DROP TABLE "Session"; 56 | 57 | -- DropTable 58 | DROP TABLE "Transaction"; 59 | 60 | -- DropTable 61 | DROP TABLE "User"; 62 | 63 | -- DropTable 64 | DROP TABLE "VerificationToken"; 65 | 66 | -- CreateTable 67 | CREATE TABLE "users" ( 68 | "id" TEXT NOT NULL, 69 | "name" TEXT, 70 | "email" TEXT, 71 | "emailVerified" TIMESTAMP(3), 72 | "image" TEXT, 73 | "role" TEXT NOT NULL DEFAULT 'user', 74 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 75 | "updatedAt" TIMESTAMP(3) NOT NULL, 76 | 77 | CONSTRAINT "users_pkey" PRIMARY KEY ("id") 78 | ); 79 | 80 | -- CreateTable 81 | CREATE TABLE "addresses" ( 82 | "id" TEXT NOT NULL, 83 | "userId" TEXT NOT NULL, 84 | "street" TEXT NOT NULL, 85 | "city" TEXT NOT NULL, 86 | "state" TEXT NOT NULL, 87 | "country" TEXT NOT NULL, 88 | "postalCode" TEXT NOT NULL, 89 | "isDefault" INTEGER NOT NULL, 90 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 91 | "updatedAt" TIMESTAMP(3), 92 | 93 | CONSTRAINT "addresses_pkey" PRIMARY KEY ("id") 94 | ); 95 | 96 | -- CreateTable 97 | CREATE TABLE "transactions" ( 98 | "id" TEXT NOT NULL, 99 | "transactionNumber" TEXT NOT NULL, 100 | "userId" TEXT NOT NULL, 101 | "status" TEXT NOT NULL DEFAULT 'PENDING', 102 | "totalItemsPrice" DOUBLE PRECISION NOT NULL, 103 | "shippingPrice" DOUBLE PRECISION NOT NULL, 104 | "shippingProvider" TEXT NOT NULL, 105 | "shippingType" TEXT NOT NULL, 106 | "addressId" TEXT NOT NULL, 107 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 108 | "updatedAt" TIMESTAMP(3), 109 | 110 | CONSTRAINT "transactions_pkey" PRIMARY KEY ("id") 111 | ); 112 | 113 | -- CreateTable 114 | CREATE TABLE "items" ( 115 | "id" TEXT NOT NULL, 116 | "productId" TEXT NOT NULL, 117 | "quantity" INTEGER NOT NULL, 118 | "transactionId" TEXT NOT NULL, 119 | "price" DOUBLE PRECISION NOT NULL, 120 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 121 | "updatedAt" TIMESTAMP(3), 122 | 123 | CONSTRAINT "items_pkey" PRIMARY KEY ("id") 124 | ); 125 | 126 | -- CreateTable 127 | CREATE TABLE "categories" ( 128 | "id" TEXT NOT NULL, 129 | "name" TEXT NOT NULL, 130 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 131 | "updatedAt" TIMESTAMP(3), 132 | 133 | CONSTRAINT "categories_pkey" PRIMARY KEY ("id") 134 | ); 135 | 136 | -- CreateTable 137 | CREATE TABLE "products" ( 138 | "id" TEXT NOT NULL, 139 | "name" TEXT NOT NULL, 140 | "description" TEXT NOT NULL, 141 | "price" DOUBLE PRECISION NOT NULL, 142 | "categoryId" TEXT NOT NULL, 143 | "image" TEXT NOT NULL, 144 | "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, 145 | "updatedAt" TIMESTAMP(3), 146 | 147 | CONSTRAINT "products_pkey" PRIMARY KEY ("id") 148 | ); 149 | 150 | -- CreateIndex 151 | CREATE UNIQUE INDEX "users_email_key" ON "users"("email"); 152 | 153 | -- CreateIndex 154 | CREATE UNIQUE INDEX "categories_name_key" ON "categories"("name"); 155 | 156 | -- AddForeignKey 157 | ALTER TABLE "addresses" ADD CONSTRAINT "addresses_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 158 | 159 | -- AddForeignKey 160 | ALTER TABLE "transactions" ADD CONSTRAINT "transactions_userId_fkey" FOREIGN KEY ("userId") REFERENCES "users"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 161 | 162 | -- AddForeignKey 163 | ALTER TABLE "transactions" ADD CONSTRAINT "transactions_addressId_fkey" FOREIGN KEY ("addressId") REFERENCES "addresses"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 164 | 165 | -- AddForeignKey 166 | ALTER TABLE "items" ADD CONSTRAINT "items_productId_fkey" FOREIGN KEY ("productId") REFERENCES "products"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 167 | 168 | -- AddForeignKey 169 | ALTER TABLE "items" ADD CONSTRAINT "items_transactionId_fkey" FOREIGN KEY ("transactionId") REFERENCES "transactions"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 170 | 171 | -- AddForeignKey 172 | ALTER TABLE "products" ADD CONSTRAINT "products_categoryId_fkey" FOREIGN KEY ("categoryId") REFERENCES "categories"("id") ON DELETE RESTRICT ON UPDATE CASCADE; 173 | --------------------------------------------------------------------------------