Git Product home page Git Product logo

adrianhajdin / ai_saas_app Goto Github PK

View Code? Open in Web Editor NEW
1.0K 8.0 312.0 459 KB

Build a REAL Software-as-a-Service app with AI features and payments & credits system that you might even turn into a side income or business idea using Next.js 14, Clerk, MongoDB, Cloudinary AI, and Stripe.

Home Page: https://jsmastery.pro

TypeScript 91.08% CSS 8.64% JavaScript 0.28%
clerk cloudinary next14 nextjs saas

ai_saas_app's Introduction

JS Mastery Pro

ai_saas_app's People

Contributors

adrianhajdin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ai_saas_app's Issues

Regarding the open source protocol of the project

Hello, I saw your project and found it to be very good after running it. I would like to use your project, but I haven't seen any open source license. What is your attitude towards this? Can you provide it for use?

Regarding the Search Image List

Regarding the search for image lists, I found that some of the titles I defined would result in an empty list when searching, and I need to change the search term. Is it because the AI has set something or there is a problem with the code?

空 comp

MongoDB and clerk web hook error

I found when I connect to webhook, clerk shows some error and mongoDB shows the data not come frome my data model. I don't know where it comes from.
mongoDB data error
model

clerk error

I'd appreciated if you can give me some feedback.

InsufficientCreditsModal.tsx

I HAVE FAILED TO FIGURE OUT WHAT COULD BE THE ISSUE .When i try to deploy to versel i get an error .Below is my code and error
CODE
"use client";

import Image from "next/image";
import { useRouter } from "next/navigation";

import {
AlertDialog,
AlertDialogAction,
AlertDialogCancel,
AlertDialogContent,
AlertDialogDescription,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogTitle,
} from "@/components/ui/alert-dialog";

export const InsufficientCreditsModal = () => {
const router = useRouter();

return (




Insufficient Credits


<AlertDialogCancel
className="border-0 p-0 hover:bg-transparent"
onClick={() => router.push("/profile")}
>
credit coins

      <Image
        src="/assets/images/stacked-coins.png"
        alt="credit coins"
        width={462}
        height={122}
      />

      <AlertDialogTitle className="p-24-bold text-dark-600">
        Oops.... Looks like you&#39;ve run out of free credits!
      </AlertDialogTitle>

      <AlertDialogDescription className="p-16-regular py-3">
        No worries, though - you can keep enjoying our services by grabbing
        more credits.
      </AlertDialogDescription>
    </AlertDialogHeader>
    <AlertDialogFooter>
      <AlertDialogCancel
        className="button w-full bg-purple-100 text-dark-400"
        onClick={() => router.push("/profile")}
      >
        No, Cancel
      </AlertDialogCancel>
      <AlertDialogAction
        className="button w-full bg-purple-gradient  bg-cover"
        onClick={() => router.push("/credits")}
      >
        Yes, Proceed
      </AlertDialogAction>
    </AlertDialogFooter>
  </AlertDialogContent>
</AlertDialog>

);
};

Error
[10:18:58.724] Running build in Washington, D.C., USA (East) – iad1
[10:18:58.909] Cloning github.com/ssemugabijames/imaginary (Branch: master, Commit: 4dc14f2)
[10:18:59.707] Cloning completed: 794.569ms
[10:19:04.698] Restored build cache
[10:19:04.921] Running "vercel build"
[10:19:05.805] Vercel CLI 33.7.1
[10:19:06.610] Installing dependencies...
[10:19:10.355]
[10:19:10.355] added 33 packages in 3s
[10:19:10.355]
[10:19:10.355] 140 packages are looking for funding
[10:19:10.355] run npm fund for details
[10:19:10.372] Detected Next.js version: 14.1.0
[10:19:10.377] Detected package-lock.json generated by npm 7+
[10:19:10.377] Running "npm run build"
[10:19:12.744]
[10:19:12.744] > [email protected] build
[10:19:12.744] > next build
[10:19:12.744]
[10:19:13.425] ▲ Next.js 14.1.0
[10:19:13.426]
[10:19:13.501] Creating an optimized production build ...
[10:19:24.551] Failed to compile.
[10:19:24.551]
[10:19:24.552] ./components/shared/InsufficientCreditsModal.ts
[10:19:24.552] Error:
[10:19:24.552] �[31mx�[0m Expected '>', got 'defaultOpen'
[10:19:24.552] ,-[�[36;1;4m/vercel/path0/components/shared/InsufficientCreditsModal.ts�[0m:18:1]
[10:19:24.552] �[2m18�[0m | const router = useRouter();
[10:19:24.552] �[2m19�[0m |
[10:19:24.552] �[2m20�[0m | return (
[10:19:24.553] �[2m21�[0m |
[10:19:24.553] : �[31;1m ^^^^^^^^^^^�[0m
[10:19:24.553] �[2m22�[0m |
[10:19:24.553] �[2m23�[0m |
[10:19:24.553] �[2m24�[0m |


[10:19:24.553] `----
[10:19:24.553]
[10:19:24.553] Caused by:
[10:19:24.553] Syntax Error
[10:19:24.553]
[10:19:24.553] Import trace for requested module:
[10:19:24.553] ./components/shared/InsufficientCreditsModal.ts
[10:19:24.553] ./components/shared/TransformationForm.tsx
[10:19:24.553]
[10:19:24.562]
[10:19:24.562] > Build failed because of webpack errors
[10:19:24.579] Error: Command "npm run build" exited with 1
[10:19:24.845]

Error: User not found

I get this error whenever I click on any of the buttons in the navbar. I thought maybe I did something wrong in my build, so I copied yours, added my .env.local, ran npm i, then npm run dev, but I get the same error. Did I make a mistake in Clerk or MongoDB?

Oddly enough, everything was fine initially. I was on the deployed version. I clicked on Generative fill, selected a picture from Unsplash, picked an aspect ration, and it transformed it, but the AI messed up, so I wanted to try a different picture. There is no cancel button, so I just clicked on the back button in the browser. After that it stopped working...

On the deployed version I get this error even on the home page.

Transformation add types issues

Hi, I found some issues happen in app/(root)/transformations/add/[types]/page.tsx
When it routes to any form we want to use it shows error.
I've tried this ai_saas_app project have same issue.
Could anyone help me to find what problems is?
error
Screenshot 1
Screenshot 2

unable to see transformed image

i have done code step by step but unable to see any transformed image in website
Screenshot (46)

unable to understand onTrasformHandler function

Facing Error after adding Collection component in the home page

I am facing this Error after adding the Collection component in the Home page

Screenshot (29)

page.tsx Code

import { Collection } from "@/components/shared/Collection"
import { navLinks } from "@/constants"
import { getAllImages } from "@/lib/actions/image.actions"
import Image from "next/image"
import Link from "next/link"

const Home = async ({ searchParams }: SearchParamProps) => {
  const page = Number(searchParams?.page) || 1;
  const searchQuery = (searchParams?.query as string) || '';

  const images = await getAllImages({ page, searchQuery})

  return (
    <>
      <section className="home">
        <h1 className="home-heading">
          Unleash Your Creative Vision with Imaginify
        </h1>
        <ul className="flex-center w-full gap-20">
          {navLinks.slice(1, 5).map((link) => (
            <Link
              key={link.route}
              href={link.route}
              className="flex-center flex-col gap-2"
            >
              <li className="flex-center w-fit rounded-full bg-white p-4">
                <Image src={link.icon} alt="image" width={24} height={24} />
              </li>
              <p className="p-14-medium text-center text-white">{link.label}</p>
            </Link>
          ))}
        </ul>
      </section>

      <section className="sm:mt-12">
        <Collection 
          hasSearch={true}
          images={images?.data}
          totalPages={images?.totalPage}
          page={page}
        />
      </section>
    </>
  )
}

export default Home

Collection.tsx

'use client'

import Image from 'next/image'
import Link from 'next/link'
import { useSearchParams, useRouter } from 'next/navigation'
import { CldImage } from 'next-cloudinary'

import {
  Pagination,
  PaginationContent,
  PaginationNext,
  PaginationPrevious,
} from '@/components/ui/pagination'
import { transformationTypes } from '@/constants'
import { IImage } from '@/lib/database/models/image.model'
import { formUrlQuery } from '@/lib/utils'

import { Button } from '../ui/button'

import { Search } from './Search'

export const Collection = ({
  hasSearch = false,
  images,
  totalPages = 1,
  page,
}: {
  images: IImage[]
  totalPages?: number
  page: number
  hasSearch?: boolean
}) => {
  const router = useRouter()
  const searchParams = useSearchParams()
  // PAGINATION HANDLER
  const onPageChange = (action: string) => {
    const pageValue = action === 'next' ? Number(page) + 1 : Number(page) - 1

    const newUrl = formUrlQuery({
      searchParams: searchParams.toString(),
      key: 'page',
      value: pageValue,
    })

    router.push(newUrl, { scroll: false })
  }

  return (
    <>
      <div className="collection-heading">
        <h2 className="h2-bold text-dark-600">Recent Edits</h2>
        {hasSearch && <Search />}
      </div>

      {images.length > 0 ? (
        <ul className="collection-list">
          {images.map((image) => (
            <Card image={image} key={image._id as string} />
          ))}
        </ul>
      ) : (
        <div className="collection-empty">
          <p className="p-20-semibold">Empty List</p>
        </div>
      )}

      {totalPages > 1 && (
        <Pagination className="mt-10">
          <PaginationContent className="flex w-full">
            <Button
              disabled={Number(page) <= 1}
              className="collection-btn"
              onClick={() => onPageChange('prev')}
            >
              <PaginationPrevious className="hover:bg-transparent hover:text-white" />
            </Button>

            <p className="flex-center p-16-medium w-fit flex-1">
              {page} / {totalPages}
            </p>

            <Button
              className="button w-32 bg-purple-gradient bg-cover text-white"
              onClick={() => onPageChange('next')}
              disabled={Number(page) >= totalPages}
            >
              <PaginationNext className="hover:bg-transparent hover:text-white" />
            </Button>
          </PaginationContent>
        </Pagination>
      )}
    </>
  )
}

const Card = ({ image }: { image: IImage }) => {
  
  return (
    <li>
      <Link href={`/transformations/${image._id}`} className="collection-card">
        <CldImage
          src={image.publicId}
          alt={image.title}
          width={image.width}
          height={image.height}
          {...image.config}
          loading="lazy"
          className="h-52 w-full rounded-[10px] object-cover"
          sizes="(max-width: 767px) 100vw, (max-width: 1279px) 50vw, 33vw"
        />
        <div className="flex-between">
          <p className="p-20-semibold mr-3 line-clamp-1 text-dark-600">
            {image.title}
          </p>
          <Image
            src={`/assets/icons/${
              transformationTypes[
                image.transformationType as TransformationTypeKey
              ].icon
            }`}
            alt={image.title}
            width={24}
            height={24}
          />
        </div>
      </Link>
    </li>
  )
}

getAllImages Action

export async function getAllImages({ limit = 9, page = 1, searchQuery = '' }: {
  limit?: number;
  page: number;
  searchQuery?: string;
}) {
  try {
    await connectToDatabase();

    cloudinary.config({
      cloud_name: process.env.NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME,
      api_key: process.env.CLOUDINARY_API_KEY,
      api_secret: process.env.CLOUDINARY_API_SECRET,
      secure: true,
    })

    let expression = 'folder=imaginify';

    if (searchQuery) {
      expression += ` AND ${searchQuery}`
    }

    const { resources } = await cloudinary.search
      .expression(expression)
      .execute();

    const resourceIds = resources.map((resource: any) => resource.public_id);

    let query = {};

    if(searchQuery) {
      query = {
        publicId: {
          $in: resourceIds
        }
      }
    }

    const skipAmount = (Number(page) -1) * limit;

    const images = await populateUser(Image.find(query))
      .sort({ updatedAt: -1 })
      .skip(skipAmount)
      .limit(limit);
    
    const totalImages = await Image.find(query).countDocuments();
    const savedImages = await Image.find().countDocuments();

    return {
      data: JSON.parse(JSON.stringify(images)),
      totalPage: Math.ceil(totalImages / limit),
      savedImages,
    }
  } catch (error) {
    handleError(error)
  }
}

Unhandled Runtime Error Error: Error:

Hello good afternoon all right? I am facing the following error when completing the ( [...]/saasai/app/(root)/transformations/add/[type]/page.tsx) settings, can you help me?

Upload preset not found

Hi Everyone, im running into this error when trying to upload any image. I have checked all of my code against adrians and even copied his pages to the T I cannot figure out where to look to find this error and correct it.
Screenshot 2024-03-02 122402

Issue with Search: does not search by image name!

The only problem I noticed is that we have a very smart search, it searches for "clouds" in pictures, but unfortunately can't search by words in the title.

Even though we put this functionality in, it doesn't work for some reason :(

So if you just search, for example: "horsey", "make", "meme" in the search results will be only "Empty list".

Transformation Pages are not rendering

At the timestamp of 1:42:39 , Whenever I tried to click one of the other options other than "home" , for example : Object Remove , Remove Background , instead of giving me with a transformation page , it says "404 not found" . I know it is a minor mistake or somehting , still dont knw , cuz im new ,so can some one pls figure me out , "Why the pages never loads , whenever i clck on any one of the optons ?"

Transformed image issue

I've been facing an issue for not seeing the transformed image, after clicking on the "apply transformation" button the transformed image section keeps loading forever and doesn't shows the transformed image and by looking through inspect it shows these errors -

image
image

but even if I try to save transformed image even without it showing on the screen by clicking the "save image" button the page loads to transformation page and the newly transformed image data also gets saved in my mongodb atlas database,

image

image

So what exactly I am facing the issue and how can I fix it as I've already checked my code with the video

User not found

Unable to create users in the database.

Unhandled Runtime Error
Error: Error: User not found

Source
lib\utils.ts (18:11) @ handleError

16 | // This is a native JavaScript error (e.g., TypeError, RangeError)
17 | console.error(error.message);

18 | throw new Error(Error: ${error.message});
| ^
19 | } else if (typeof error === "string") {
20 | // This is a string error message
21 | console.error(error);

Error: Error: User with clerkId user_2kQEy3NVpSvdKbiMsH2yBVKhHof not found

HERE IS MY CODES " "use server";

import { revalidatePath } from "next/cache";

import User from "../database/models/user.model";
import { connectToDatabase } from "../database/mongose";
import { handleError } from "../utils";

// CREATE
export async function createUser(user: CreateUserParams) {
try {
await connectToDatabase();

const newUser = await User.create(user);

return JSON.parse(JSON.stringify(newUser));

} catch (error) {
handleError(error);
}
}

// READ
export async function getUserById(userId: string) {
try {
await connectToDatabase();

console.log(`Fetching user with clerkId: ${userId}`); // Log userId
const user = await User.findOne({ clerkId: userId });

if (!user) {
  console.error(`User not found with clerkId: ${userId}`); // Log error
  throw new Error(`User with clerkId ${userId} not found`);
}

return JSON.parse(JSON.stringify(user));

} catch (error) {
handleError(error);
}
}

// UPDATE
export async function updateUser(clerkId: string, user: UpdateUserParams) {
try {
await connectToDatabase();

console.log(`Updating user with clerkId: ${clerkId}`); // Log clerkId
const updatedUser = await User.findOneAndUpdate({ clerkId }, user, {
  new: true,
});

if (!updatedUser) {
  console.error(`User update failed for clerkId: ${clerkId}`); // Log error
  throw new Error(`User update failed for clerkId ${clerkId}`);
}

return JSON.parse(JSON.stringify(updatedUser));

} catch (error) {
handleError(error);
}
}

// DELETE
export async function deleteUser(clerkId: string) {
try {
await connectToDatabase();

console.log(`Deleting user with clerkId: ${clerkId}`); // Log clerkId
const userToDelete = await User.findOne({ clerkId });

if (!userToDelete) {
  console.error(`User not found for deletion with clerkId: ${clerkId}`); // Log error
  throw new Error(`User not found with clerkId ${clerkId}`);
}

const deletedUser = await User.findByIdAndDelete(userToDelete._id);
revalidatePath("/");

return deletedUser ? JSON.parse(JSON.stringify(deletedUser)) : null;

} catch (error) {
handleError(error);
}
}

// USE CREDITS
export async function updateCredits(userId: string, creditFee: number) {
try {
await connectToDatabase();

console.log(`Updating credits for user with _id: ${userId}`); // Log userId
const updatedUserCredits = await User.findOneAndUpdate(
  { _id: userId },
  { $inc: { creditBalance: creditFee }},
  { new: true }
);

if (!updatedUserCredits) {
  console.error(`User credits update failed for _id: ${userId}`); // Log error
  throw new Error(`User credits update failed for _id ${userId}`);
}

return JSON.parse(JSON.stringify(updatedUserCredits));

} catch (error) {
handleError(error);
}
}
" @adrianhajdin
Screenshot 2024-08-10 123827

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.