Skip to content

Commit

Permalink
Merge pull request #4 from vimalsonara/correction
Browse files Browse the repository at this point in the history
Correction
  • Loading branch information
vimalsonara authored Nov 15, 2023
2 parents 462f002 + c9793ba commit f5922eb
Show file tree
Hide file tree
Showing 17 changed files with 132 additions and 276 deletions.
File renamed without changes.
92 changes: 92 additions & 0 deletions app/(auth)/signup/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
"use client";

import axios from "axios";
import { useForm, SubmitHandler } from "react-hook-form";

type Inputs = {
name: string;
email: string;
password: string;
confirmPassword: string;
};

export default function Signup() {
const {
register,
handleSubmit,
formState: { errors },
} = useForm<Inputs>();
const onSubmit: SubmitHandler<Inputs> = async (data) => {
console.log(data);

if (data.password !== data.confirmPassword) {
console.log("password not matched");
}

try {
const response = await axios.post("/api/user/signup", {
data,
});
console.log(response);
} catch (error) {}
};

return (
<div className="flex min-h-screen w-screen flex-col items-center justify-center">
<form
onSubmit={handleSubmit(onSubmit)}
className="flex flex-col gap-2 border p-5 rounded-lg"
>
<input
type="text"
placeholder="name"
{...register("name", { required: true })}
className={
errors.name
? "border-2 border-red-500 rounded p-1 outline-none"
: "rounded p-1 outline-none "
}
/>
{errors.name && <span className="text-red-500">Name required</span>}
<input
type="email"
placeholder="email"
{...register("email", { required: true })}
className={
errors.email
? "border-2 border-red-500 rounded p-1 outline-none"
: "rounded p-1 outline-none "
}
/>
{errors.email && <span className="text-red-500">Email required</span>}
<input
type="password"
placeholder="password"
{...register("password", { required: true })}
className={
errors.password
? "border-2 border-red-500 rounded p-1 outline-none"
: "rounded p-1 outline-none "
}
/>
{errors.password && (
<span className="text-red-500">Password required</span>
)}
<input
type="password"
placeholder="confirmPassword"
{...register("confirmPassword", { required: true })}
className={
errors.confirmPassword
? "border-2 border-red-500 rounded p-1 outline-none"
: "rounded p-1 outline-none "
}
/>
{errors.confirmPassword && (
<span className="text-red-500">Confirm password required</span>
)}
<input type="submit" className="bg-blue-500 rounded-md py-1" />
</form>
</div>
);
}
2 changes: 1 addition & 1 deletion app/api/auth/[...nextauth]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export const authOptions: NextAuthOptions = {
strategy: "jwt",
},
pages: {
signIn: "/auth/login",
signIn: "/login",
},
};

Expand Down
7 changes: 1 addition & 6 deletions app/api/product/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../../auth/[...nextauth]/route";
import { db } from "@/lib/firebaseConfig";
import { collection, getDocs, query, where } from "firebase/firestore";

interface Product {
product: string;
userId: string;
id: string;
}
import { Product } from "@/types/types";

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand Down
14 changes: 4 additions & 10 deletions app/api/product/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { getServerSession } from "next-auth";
import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../auth/[...nextauth]/route";
import connectDB from "@/lib/db";
import { db } from "@/lib/firebaseConfig";
import {
addDoc,
Expand All @@ -10,13 +9,7 @@ import {
serverTimestamp,
where,
} from "firebase/firestore";

connectDB();

interface Product {
productName: string;
userId: string;
}
import { Product } from "@/types/types";

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand All @@ -32,14 +25,15 @@ export async function POST(req: NextRequest) {
snapshot.docs.forEach((doc) => {
const productData = doc.data();
const currentProduct: Product = {
productName: productData.product,
product: productData.product,
userId: productData.userId,
id: productData.id,
};
products.push(currentProduct);
});

const productExist = products.find(
(p) => p.productName === product && p.userId === userId
(p) => p.product === product && p.userId === userId
);
if (productExist) {
return NextResponse.json(
Expand Down
18 changes: 1 addition & 17 deletions app/api/purchase/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,7 @@ import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../../auth/[...nextauth]/route";
import { collection, getDocs } from "firebase/firestore";
import { db } from "@/lib/firebaseConfig";
import PurchaseEntry from "@/models/purchase";

interface Items {
itemName: string;
price: string;
quantity: string;
}

export interface Purchase {
id: string;
date: string;
totalAmount: number;
userId: string;
vendorId: string;
vendorName: string;
items: Items[];
}
import { Purchase } from "@/types/types";

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand Down
2 changes: 1 addition & 1 deletion app/api/purchase/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { authOptions } from "../auth/[...nextauth]/route";
import PurchaseEntry from "@/models/purchase";
import { addDoc, collection, getDocs } from "firebase/firestore";
import { db } from "@/lib/firebaseConfig";
import { Purchase } from "@/app/api/purchase/list/route";
import { Purchase } from "@/types/types";

// add new purchase
export async function POST(req: NextRequest) {
Expand Down
8 changes: 1 addition & 7 deletions app/api/vendor/list/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@ import { NextRequest, NextResponse } from "next/server";
import { authOptions } from "../../auth/[...nextauth]/route";
import { collection, getDocs, query, where } from "firebase/firestore";
import { db } from "@/lib/firebaseConfig";

interface Vendor {
id: string;
vendorName: string;
userId: string;
mobile: string;
}
import { Vendor } from "@/types/types";

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand Down
8 changes: 2 additions & 6 deletions app/api/vendor/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,7 @@ import {
serverTimestamp,
} from "firebase/firestore";
import { db } from "@/lib/firebaseConfig";

interface Vendor {
mobile: string;
userId: string;
vendorName: string;
}
import { Vendor } from "@/types/types";

export async function POST(req: NextRequest) {
const session = await getServerSession(authOptions);
Expand All @@ -33,6 +28,7 @@ export async function POST(req: NextRequest) {
vendorName: vendorData.vendorName,
mobile: vendorData.mobile,
userId: vendorData.userId,
id: vendorData.id,
};
vendors.push(currentVendor);
});
Expand Down
90 changes: 0 additions & 90 deletions app/auth/signup/page.tsx

This file was deleted.

13 changes: 0 additions & 13 deletions lib/db.ts

This file was deleted.

2 changes: 1 addition & 1 deletion middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export default withAuth(
const pathname = req.nextUrl.pathname;
const protectedRoutes = config.matcher;
if (protectedRoutes.includes(pathname) && !req.nextauth.token) {
return NextResponse.rewrite(new URL("/auth/login"));
return NextResponse.rewrite(new URL("/login"));
}
},
{
Expand Down
21 changes: 0 additions & 21 deletions models/product.ts

This file was deleted.

Loading

0 comments on commit f5922eb

Please sign in to comment.