diff --git a/app/api/users/route.ts b/app/api/users/route.ts new file mode 100644 index 0000000..61f0032 --- /dev/null +++ b/app/api/users/route.ts @@ -0,0 +1,18 @@ +import { NextRequest, NextResponse } from "next/server"; +import connectDb from "@/app/util/connectDb"; +import { checkValidityOfToken } from "@/app/util/checkValidityOfToken"; +import USER from "@/app/models/userSchema"; +export async function GET(req:NextRequest) { + try { + const decodedToken = checkValidityOfToken(req); + if (!decodedToken.success) return NextResponse.json(decodedToken, { status: 401 }); + const email = decodedToken?.email; + await connectDb(); + const getUsers=await USER.find({isVerified:true}).select('-password -verifyOtp -verifyOtpExpiry') + const filterTheRequestedUser=getUsers.filter(user=>user.email!==email) + return NextResponse.json({success:true,message:'Fetched users successfully',users:filterTheRequestedUser},{status:200}) + } catch (error) { + console.log(error) + return NextResponse.json({success:false,message:'Could not fetch users, try again!'},{status:500}) + } +} \ No newline at end of file diff --git a/app/register/page.tsx b/app/register/page.tsx index 59b2cc9..74672a0 100644 --- a/app/register/page.tsx +++ b/app/register/page.tsx @@ -26,14 +26,14 @@ async function registerUser(){ toast.success(data.message) router.push('/verifyOtp') } - else if(data.error){ - toast.error(data.error.issues[0].message) + else if(data.validation){ + toast.error(data.validation.error.issues.map((issue:any)=>issue.message).join(', ')) } + else{ toast.error(data.message) } setLoading(false) - console.log(data) } return (
diff --git a/app/ui/CreateMemoryDialog.tsx b/app/ui/CreateMemoryDialog.tsx new file mode 100644 index 0000000..20f3f57 --- /dev/null +++ b/app/ui/CreateMemoryDialog.tsx @@ -0,0 +1,142 @@ +'use client' +import { Fragment, useRef, useState } from 'react' +import { Dialog, Transition } from '@headlessui/react' +import { ExclamationTriangleIcon } from '@heroicons/react/24/outline' +import { CldUploadWidget } from 'next-cloudinary' +import toast from 'react-hot-toast' +import Image from 'next/image' +export default function CreateMemoryDialog({open,setOpen}:any) { + const [title,setTitle]=useState('') + const [description,setDescription]=useState('') + const [coverPicUrl,setCoverPicUrl]=useState('') + + const cancelButtonRef = useRef(null) +async function createMemory(){ + const response=await fetch('/api/memories/createMemories',{ + method:'POST', + headers:{ + 'Content-Type':'application/json' + }, + body:JSON.stringify({ + title, + description, + memoryCoverPic:coverPicUrl, + memoryParticipants:[], + }) + }) + const data=await response.json() + if(data.success){ + toast.success(data.message) + setOpen(false) + } + else{ + toast.error(data.message) + } +} + + return ( + + + +
+ + +
+
+ + +
+

Create a Memory.

+
{ + e.preventDefault(); + createMemory() + }}> +
+ + setTitle(e.target.value)} + > +
+
+ + +
+
+ +
+ { + setCoverPicUrl(results?.info?.secure_url) + }}> + {({ open,isLoading }) => { + return ( + <> + {isLoading? + + : + } + + ); + }} + +
+ {coverPicUrl && {title}/} +
+
+ +
+ + +
+
+
+ +
+
+
+
+
+
+ ) +} diff --git a/app/ui/Navbar.tsx b/app/ui/Navbar.tsx index f73b440..be52bcd 100644 --- a/app/ui/Navbar.tsx +++ b/app/ui/Navbar.tsx @@ -5,6 +5,7 @@ import { Bars3Icon, XMarkIcon } from '@heroicons/react/24/outline' import Image from 'next/image' import { useRouter } from "next/navigation"; import toast from 'react-hot-toast' +import CreateMemoryDialog from './CreateMemoryDialog' // import { CldUploadWidget } from 'next-cloudinary' function classNames(...classes:string[]) { return classes.filter(Boolean).join(' ') @@ -14,6 +15,7 @@ function classNames(...classes:string[]) { export default function Navbar() { const router=useRouter() const [imageUrl,setImageUrl]=useState([]) + const [open, setOpen] = useState(false) async function logout(){ const response=await fetch('/api/auth/logout',{ @@ -29,6 +31,7 @@ export default function Navbar() { } } return ( + <> {({ open }) => ( <> @@ -73,7 +76,7 @@ export default function Navbar() { -Create a Memory +setOpen(true)}>Create a Memory {/* { setImageUrl((prevImages)=>[...prevImages,{fileName:results?.info?.original_filename, fileUrl:results?.info?.secure_url}]) @@ -166,5 +169,7 @@ export default function Navbar() { )} + + ) } diff --git a/app/verifyOtp/page.tsx b/app/verifyOtp/page.tsx index 6cddb97..e6be0ee 100644 --- a/app/verifyOtp/page.tsx +++ b/app/verifyOtp/page.tsx @@ -70,7 +70,6 @@ function Page() { } else { toast.error(data.message); } - console.log(data); }; return ( diff --git a/next.config.mjs b/next.config.mjs index 40c7911..617c741 100644 --- a/next.config.mjs +++ b/next.config.mjs @@ -1,7 +1,7 @@ /** @type {import('next').NextConfig} */ const nextConfig = { images:{ - domains:['tailwindui.com','images.unsplash.com'] + domains:['tailwindui.com','images.unsplash.com','res.cloudinary.com'] } }; diff --git a/package-lock.json b/package-lock.json index c2f0d62..0b2f581 100644 --- a/package-lock.json +++ b/package-lock.json @@ -16,6 +16,7 @@ "mongoose": "^8.4.0", "next": "14.2.3", "next-cloudinary": "^6.5.2", + "nodemailer": "^6.9.13", "react": "^18", "react-dom": "^18", "react-hot-toast": "^2.4.1" @@ -3956,6 +3957,14 @@ } } }, + "node_modules/nodemailer": { + "version": "6.9.13", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.13.tgz", + "integrity": "sha512-7o38Yogx6krdoBf3jCAqnIN4oSQFx+fMa0I7dK1D+me9kBxx12D+/33wSb+fhOCtIxvYJ+4x4IMEhmhCKfAiOA==", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/nopt": { "version": "5.0.0", "resolved": "https://registry.npmjs.org/nopt/-/nopt-5.0.0.tgz", diff --git a/package.json b/package.json index 9e63fef..e7d64c9 100644 --- a/package.json +++ b/package.json @@ -17,6 +17,7 @@ "mongoose": "^8.4.0", "next": "14.2.3", "next-cloudinary": "^6.5.2", + "nodemailer": "^6.9.13", "react": "^18", "react-dom": "^18", "react-hot-toast": "^2.4.1"