<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rajarshi Misra</title>
    <description>The latest articles on DEV Community by Rajarshi Misra (@rajarshimisra).</description>
    <link>https://dev.to/rajarshimisra</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1197091%2F472b3a99-49a5-435c-b2f9-2871c6d47d5a.png</url>
      <title>DEV Community: Rajarshi Misra</title>
      <link>https://dev.to/rajarshimisra</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rajarshimisra"/>
    <language>en</language>
    <item>
      <title>Building an AI webapp(HomeDec) with Hanko, NextJS, Prisma, Supabase and Replicate</title>
      <dc:creator>Rajarshi Misra</dc:creator>
      <pubDate>Mon, 30 Oct 2023 15:29:50 +0000</pubDate>
      <link>https://dev.to/rajarshimisra/building-an-ai-webapphomedec-with-hanko-nextjs-prisma-supabase-and-replicate-29cd</link>
      <guid>https://dev.to/rajarshimisra/building-an-ai-webapphomedec-with-hanko-nextjs-prisma-supabase-and-replicate-29cd</guid>
      <description>&lt;p&gt;This is a tutorial on creating an AI webapp(I like to call it HomeDec :)) to enhance room designs.&lt;br&gt;
The app would have the following functionalities:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;It would let the user login using passkey or password. It has been done using &lt;a href="//hanko.io"&gt;Hanko&lt;/a&gt;.&lt;/li&gt;
&lt;li&gt;Then display the dashboard page.&lt;/li&gt;
&lt;li&gt;The dashboard contains a form to upload images to render the designs and display the previously rendered designs.&lt;/li&gt;
&lt;li&gt;And then options for profile management and logout, implemented using Hanko.&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Let's Begin...
&lt;/h2&gt;

&lt;p&gt;First let's begin with the stack used for the app.&lt;/p&gt;
&lt;h3&gt;
  
  
  NextJS
&lt;/h3&gt;

&lt;p&gt;I've got really comfortable with this framework and like the support from Vercel. Do check &lt;a href="https://docs.hanko.io/quickstarts/fullstack/next"&gt;this out&lt;/a&gt;&lt;br&gt;
NextJS is a React framework for fullstack application built by Vercel:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Used by some of the world's largest companies, Next.js enables you to create full-stack Web applications by extending the latest React features, and integrating powerful Rust-based JavaScript tooling for the fastest builds.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  TailwindCSS
&lt;/h3&gt;

&lt;p&gt;Tailwind CSS helps you minimize the use of CSS stylesheets. You can use Tailwind classes to style various components&lt;/p&gt;
&lt;h3&gt;
  
  
  MaterialUI
&lt;/h3&gt;

&lt;p&gt;It's a React component library, developed by Google. It would help you build your UI faster.&lt;/p&gt;
&lt;h3&gt;
  
  
  Prisma
&lt;/h3&gt;

&lt;p&gt;The application doesn't require a complicated DB. So, Prisma is perfect for that.&lt;/p&gt;
&lt;h3&gt;
  
  
  Supabase
&lt;/h3&gt;

&lt;p&gt;Supabase has been used for PostgreSQL hosting which could be directly accessed by Figma. Further, Supabase storage has been used to store the images.&lt;/p&gt;
&lt;h3&gt;
  
  
  Replicate
&lt;/h3&gt;

&lt;p&gt;Replicate allows you to run machine learning models in the cloud.&lt;/p&gt;
&lt;h3&gt;
  
  
  Vercel
&lt;/h3&gt;

&lt;p&gt;Vercel lets you deploy webpages easily.&lt;/p&gt;
&lt;h2&gt;
  
  
  Build Start...
&lt;/h2&gt;

&lt;p&gt;Hanko has already provided a&lt;a href="https://github.com/teamhanko/hanko-nextjs-starter"&gt; NextJS starter pack&lt;/a&gt;. We'll start with that to save us time and reduce the chance of getting any error.&lt;/p&gt;

&lt;p&gt;Open your terminal and run the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git clone https://github.com/teamhanko/hanko-nextjs-starter.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This repository comes with a &lt;code&gt;pnpm-lock.yaml&lt;/code&gt; file. So we are going to install the required dependencies using &lt;code&gt;pnpm&lt;/code&gt;. Check &lt;a href="https://pnpm.io/"&gt;this&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Then run the following commands on your terminal&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cd hanko-nextjs-starter
pnpm install
pnpm run dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This would start the project on &lt;code&gt;localhost://3000&lt;/code&gt;&lt;br&gt;
You should get a screen like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mJkYqOep--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjgr8y9wsa2uqirxe0w6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mJkYqOep--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/gjgr8y9wsa2uqirxe0w6.png" alt="Image description" width="800" height="270"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On clicking Login you will be directed to a login page. However, it would display an error. This is because we haven't set up Hanko url yet.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KQHx77_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7b6w2fr6i64wxs5eebp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KQHx77_x--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p7b6w2fr6i64wxs5eebp.png" alt="Image description" width="547" height="318"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Authentication By Hanko
&lt;/h2&gt;

&lt;p&gt;It's necessary to setup Hanko to be able to use the application&lt;/p&gt;
&lt;h3&gt;
  
  
  Hanko Cloud Setup
&lt;/h3&gt;

&lt;p&gt;Visit &lt;a href="https://cloud.hanko.io/login"&gt;Hanko Cloud&lt;/a&gt; and create an account&lt;br&gt;
First create a new organization&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CObD_YzY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8h8afd2bt555se91va88.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CObD_YzY--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8h8afd2bt555se91va88.png" alt="Image description" width="800" height="488"&gt;&lt;/a&gt;&lt;br&gt;
And then create a new project. In the app URL add your development URL(could be &lt;a href="http://localhost:3000"&gt;http://localhost:3000&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--tphw5vcy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xu176ejx3guuwm8qgm7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--tphw5vcy--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6xu176ejx3guuwm8qgm7.png" alt="Image description" width="778" height="812"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll get your dashboard. You will also get your API URL to be used in your project.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fzvjibj0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7sr23isabguia316fhc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fzvjibj0--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b7sr23isabguia316fhc.png" alt="Image description" width="800" height="449"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Understanding the structure of NextJS Starter Pack
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fXAUenG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka4rmpd8g3qnhfu4grpi.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fXAUenG8--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ka4rmpd8g3qnhfu4grpi.png" alt="Image description" width="800" height="510"&gt;&lt;/a&gt;&lt;br&gt;
The starter pack is the usual NextJS project structure. It has got app directory, component directory and public directory. Also, we need to change the .env.example to .env.local. And then paste the Hanko API url obtained from the dashboard&lt;/p&gt;

&lt;p&gt;We'll mainly need to understand the &lt;code&gt;components/&lt;/code&gt; and &lt;code&gt;app/&lt;/code&gt; in order to customise it for our application.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;app directory&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--AWQ4wZoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yw5l4x2igs75me3zni6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--AWQ4wZoN--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yw5l4x2igs75me3zni6b.png" alt="Image description" width="353" height="360"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The app directory contains the &lt;code&gt;page.jsx&lt;/code&gt; and &lt;code&gt;dashboard&lt;/code&gt; and &lt;code&gt;login&lt;/code&gt; directories. The &lt;code&gt;page.jsx&lt;/code&gt; is the homepage of the application. The login page contains the Hanko login component:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--xnN0siyC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpu62vdgsaozgt8gas7x.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--xnN0siyC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hpu62vdgsaozgt8gas7x.png" alt="Image description" width="800" height="202"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;On successful login, the web app redirects to dashboard page. The dashboard page is rendered by the &lt;code&gt;page.tsx&lt;/code&gt; file in the &lt;code&gt;dashboard/&lt;/code&gt; directory. Currently, it contains just the HankoProfile component and Logout component.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--lG__A_0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/np28xukmcu2hlch56rfk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--lG__A_0p--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/np28xukmcu2hlch56rfk.png" alt="Image description" width="800" height="193"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Checkout this link to the &lt;a href="https://hanko-nextjs-starter-six.vercel.app/dashboard"&gt;hanko-nextjs-starter app&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;component directory&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eY7ooNRT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8r11jyr1rad9mj1amx4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eY7ooNRT--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a8r11jyr1rad9mj1amx4.png" alt="Image description" width="362" height="212"&gt;&lt;/a&gt;&lt;br&gt;
This is an overview of the component directory. As we go on customizing the UI, we'll understand it even better.&lt;/p&gt;

&lt;p&gt;Further, guys at Hanko have already setup Tailwind for us and have reduced a lot of our work.&lt;/p&gt;
&lt;h2&gt;
  
  
  Building the UI
&lt;/h2&gt;

&lt;p&gt;As mentioned before we are going to use MaterialUI to speed up our development. We'll also use Materical Icons.&lt;br&gt;
Run the following command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install @mui/icons-material @mui/material @emotion/styled @emotion/react
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Lets begin with &lt;code&gt;app/page.tsx&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import Button from "@mui/material/Button";
import ArrowForwardIosIcon from "@mui/icons-material/ArrowForwardIos";
export default function Login() {
  return (
    &amp;lt;div className="flex flex-col min-h-screen justify-center items-center bg-black"&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div className="sm:text-9xl text-6xl text-white"&amp;gt;HOMEDEC&amp;lt;/div&amp;gt;
        &amp;lt;div className="sm:text-5xl text-white"&amp;gt;
          AI HOME DECORATOR FOR ALL YOUR NEEDS
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;Button
        variant="contained"
        href="/login  "
        className="text-4xl flex mt-20"
      &amp;gt;
        GET STARTED
        &amp;lt;ArrowForwardIosIcon /&amp;gt;
      &amp;lt;/Button&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should turn the homepage into something like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--3Co2mShC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgzzuccfnahoabkd8nhg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--3Co2mShC--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mgzzuccfnahoabkd8nhg.png" alt="Image description" width="800" height="377"&gt;&lt;/a&gt;&lt;br&gt;
The UI is pretty basic. But, the purpose of this project was to understand how Hanko and Supabase work.&lt;/p&gt;

&lt;p&gt;Next, we'll work on the login page. But, before that lets check the HankoAuth component.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useEffect, useCallback, useState } from "react";
import { useRouter } from "next/navigation";
import { register, Hanko } from "@teamhanko/hanko-elements";

const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_KEY || "";

export default function HankoAuth() {
  const router = useRouter();

  const [hanko, setHanko] = useState&amp;lt;Hanko&amp;gt;();

  useEffect(() =&amp;gt; {
    import("@teamhanko/hanko-elements").then(({ Hanko }) =&amp;gt;
      setHanko(new Hanko(hankoApi))
    );
  }, []);

  const redirectAfterLogin = useCallback(() =&amp;gt; {
    // successfully logged in, redirect to a page in your application
    router.replace("/dashboard");
  }, [router]);

  useEffect(
    () =&amp;gt;
      hanko?.onAuthFlowCompleted(() =&amp;gt; {
        redirectAfterLogin();
      }),
    [hanko, redirectAfterLogin]
  );

  useEffect(() =&amp;gt; {
    register(hankoApi).catch((error) =&amp;gt; {
      // handle error
    });
  }, []);

  return &amp;lt;hanko-auth /&amp;gt;;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The HankoAuth component is perfectly ready for us to use in our project. So, lets focus on customizing the &lt;code&gt;/login/page.tsx&lt;/code&gt; page:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import dynamic from "next/dynamic";
const HankoAuth = dynamic(
  () =&amp;gt; import("@/components/hanko-components/HankoAuth"),
  { ssr: false }
);

export default function Login() {

  return (
    &amp;lt;div className="flex min-h-screen justify-center items-center bg-black"&amp;gt;
      &amp;lt;div className="bg-white sm:p-5 rounded-2xl shadow-md"&amp;gt;
        &amp;lt;HankoAuth /&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll also customize the styling a bit for the login component. Add the following to the app/globals.css file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;:root {
  --border-radius: 20px;
  --brand-color: #1976d2;
  --brand-color-shade-1: #042c55;
  --brand-color-shade-2: #88bff7;
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You should get this page on clicking the &lt;strong&gt;GET STARTED&lt;/strong&gt; button.&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--fFCXKtR1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tymqtxk5ig9d3brha3e4.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--fFCXKtR1--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tymqtxk5ig9d3brha3e4.png" alt="Image description" width="800" height="380"&gt;&lt;/a&gt;&lt;br&gt;
On successful login, you should be directed to &lt;code&gt;/dashboard&lt;/code&gt; page. We'll first create components for the dashboard page.&lt;br&gt;
The first component will be components/Form.tsx&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import Button from "@mui/material/Button";
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
import { styled } from "@mui/material/styles";
import * as React from "react";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import { useRouter } from "next/navigation"; //this for use later


const VisuallyHiddenInput = styled("input")({
  clip: "rect(0 0 0 0)",
  clipPath: "inset(50%)",
  height: 1,
  overflow: "hidden",
  position: "absolute",
  bottom: 0,
  left: 0,
  whiteSpace: "nowrap",
  width: 1,
});
const currencies = [
  {
    value: "Living Room",
    label: "Living Room",
  },
  {
    value: "Store",
    label: "Store",
  },
  {
    value: "Bedroom",
    label: "Bedroom",
  },
  {
    value: "Bathroom",
    label: "Bathroom",
  },
  {
    value: "Office",
    label: "Office",
  },
  {
    value: "Kitchen",
    label: "Kitchen",
  },

  {
    value: "Balcony",
    label: "Balcony",
  },
];

export const Form = () =&amp;gt; {
  const [loading, setLoading] = React.useState(false);
  const [file, setFile] = React.useState&amp;lt;File&amp;gt;();
  const [name, setName] = React.useState("Nothing");
  const [uploadUrl, setUploadUrl] = React.useState("");
  const [valuee, setValuee] = React.useState("Living Room");
  const [value, setValue] = React.useState("");
  return (
    &amp;lt;div className=" space-y-12 "&amp;gt;
      &amp;lt;div className="text-lg font-medium"&amp;gt;
        Upload an image and tell us what you want for your room.
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div className="space-y-4"&amp;gt;
          &amp;lt;Button
            component="label"
            variant="contained"
            startIcon={&amp;lt;CloudUploadIcon /&amp;gt;}
          &amp;gt;
            &amp;lt;div className="font-bold text-xl"&amp;gt;Upload file&amp;lt;/div&amp;gt;
            &amp;lt;VisuallyHiddenInput
              type="file"
              accept=".png"
              onChange={(e) =&amp;gt; {
                setName(e.target.files![0].name);
                setFile(e.target.files![0]);
              }}
            /&amp;gt;
          &amp;lt;/Button&amp;gt;
          &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;
          &amp;lt;div&amp;gt;{name} uploaded!&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div className="text-white"&amp;gt;
          &amp;lt;TextField
            id="outlined-basic"
            label={&amp;lt;div style={{ color: "#1976D2" }}&amp;gt;Tell us more&amp;lt;/div&amp;gt;}
            variant="outlined"
            maxRows="3"
            multiline
            value={value}
            onChange={(e) =&amp;gt; {
              setValue(e.target.value);
            }}
            sx={{ width: "80%" }}
            inputProps={{ style: { color: "white" } }}
            focused
          /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div style={{ width: "100%" }}&amp;gt;
          &amp;lt;TextField
            id="outlined-select-currency"
            select
            label="Select Room Type"
            defaultValue="Living Room"
            value={valuee}
            helperText="Please select your currency"
            sx={{ width: "80%" }}
            focused
            SelectProps={{ style: { color: "white" } }}
            onChange={(e) =&amp;gt; {
              setValuee(e.target.value);
            }}
          &amp;gt;
            {currencies.map((option) =&amp;gt; (
              &amp;lt;MenuItem key={option.value} value={option.value}&amp;gt;
                {option.label}
              &amp;lt;/MenuItem&amp;gt;
            ))}
          &amp;lt;/TextField&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;Button
          variant="contained"
          onClick={(e) =&amp;gt; {
            if (file != null) {
              {

              }
            } else {
              window.alert("You need to upload an image");
            }
          }}
        &amp;gt;
          {!loading ? (
            &amp;lt;div className="font-bold text-xl"&amp;gt;RENDER DESIGNS&amp;lt;/div&amp;gt;
          ) : (
            &amp;lt;div className="font-bold text-xl"&amp;gt;PLEASE WAIT..&amp;lt;/div&amp;gt;
          )}
        &amp;lt;/Button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then, we'll create the Profile component &lt;code&gt;components/Form.tsx&lt;/code&gt;. Try to figure out how the profile modal would close XD.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useEffect, useState } from "react";
import { register } from "@teamhanko/hanko-elements";
import ManageAccountsIcon from "@mui/icons-material/ManageAccounts";
const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_KEY;

export const Profile = () =&amp;gt; {
  const [openState, setOpenState] = useState(false);

  useEffect(() =&amp;gt; {
    register(hankoApi ?? "").catch((error) =&amp;gt; {
      console.log(error);
    });
  }, []);

  const openProfile = () =&amp;gt; {
    setOpenState(!openState);
  };

  return (
    &amp;lt;&amp;gt;
      &amp;lt;button
        type="button"
        onClick={openProfile}
        className="font-bold text-2xl"
      &amp;gt;
        &amp;lt;ManageAccountsIcon fontSize="large" /&amp;gt;
        PROFILE
      &amp;lt;/button&amp;gt;
      {openState &amp;amp;&amp;amp; (
        &amp;lt;div className=" absolute top-14 "&amp;gt;
          &amp;lt;section className=" w-[450px] h-auto rounded-2xl bg-white p-5"&amp;gt;
            &amp;lt;hanko-profile /&amp;gt;
          &amp;lt;/section&amp;gt;
        &amp;lt;/div&amp;gt;
      )}
    &amp;lt;/&amp;gt;
  );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then finally the &lt;code&gt;components/Logout.tsx&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import { useState, useEffect, useCallback } from "react";
import { useRouter } from "next/navigation";
import { Hanko } from "@teamhanko/hanko-elements";
import LogoutIcon from "@mui/icons-material/Logout";

const hankoApi = process.env.NEXT_PUBLIC_HANKO_API_KEY;

export const Logout = () =&amp;gt; {
  const router = useRouter();
  const [hanko, setHanko] = useState&amp;lt;Hanko&amp;gt;();

  useEffect(() =&amp;gt; {
    import("@teamhanko/hanko-elements").then(({ Hanko }) =&amp;gt;
      setHanko(new Hanko(hankoApi ?? ""))
    );
  }, []);

  const logout = () =&amp;gt; {
    hanko?.user
      .logout()
      .then(() =&amp;gt; {})
      .catch((error) =&amp;gt; {
        console.log(error);
      });
    router.push("/");
    router.refresh();
  };
  return (
    &amp;lt;&amp;gt;
      &amp;lt;button type="button" onClick={logout} className="font-bold text-2xl"&amp;gt;
        &amp;lt;LogoutIcon fontSize="large" /&amp;gt;
        LOGOUT
      &amp;lt;/button&amp;gt;
    &amp;lt;/&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Finally, we combine everything into pages/dashboard.tsx:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Logout } from "@/components/Logout";
import { Profile } from "@/components/Profile";
import { Form } from "@/components/Form";
import Card from "@mui/material/Card";
import CardActions from "@mui/material/CardActions";
import CardMedia from "@mui/material/CardMedia";

export default async function Todo() {
  return (
    &amp;lt;main className="bg-black text-white"&amp;gt;
      &amp;lt;div className="w-full flex py-8 px-12 space-x-6 justify-around"&amp;gt;
        &amp;lt;Profile /&amp;gt;
        &amp;lt;div className="font-bold sm:text-4xl text-2xl"&amp;gt;
          &amp;lt;a href="/"&amp;gt;HOMEDEC&amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;Logout /&amp;gt;
      &amp;lt;/div&amp;gt;
      {/* &amp;lt;div className="bg-slate-300 rounded-3xl py-6  h-[400px] w-[450px] flex flex-col text-slate-800"&amp;gt;
        &amp;lt;h1 className="text-3xl text-center"&amp;gt;My to dos&amp;lt;/h1&amp;gt;
        &amp;lt;NewTodo /&amp;gt;
        &amp;lt;ul className="px-6"&amp;gt;
          &amp;lt;TodoItem todos={todos} /&amp;gt;
        &amp;lt;/ul&amp;gt;
      &amp;lt;/div&amp;gt; */}
      &amp;lt;div className="sm:grid grid-cols-3 gap-x-4 px-16 py-20"&amp;gt;
        &amp;lt;div className="col-span-1 pr-6 text-center"&amp;gt;
          &amp;lt;Form /&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div className="col-span-2 space-y-4"&amp;gt;
          &amp;lt;div className="text-3xl p-4 font-bold"&amp;gt;YOUR DESIGNS&amp;lt;/div&amp;gt;
          &amp;lt;div className="sm:grid grid-cols-2 space-y-4"&amp;gt;
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This should render a UI like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--w64avvMc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jtjk9s1s0d91l7673bh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--w64avvMc--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3jtjk9s1s0d91l7673bh.png" alt="Image description" width="800" height="386"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now, we are done setting up the basic UI. Time to move to the next parts.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Prisma and Supabase
&lt;/h2&gt;

&lt;p&gt;First thing, install Prisma:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm install prisma
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Set up prisma with the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm prisma init --datasource-provider postgresql
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will generate a prisma directory. In that directory, customise the schema.prisma file as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// This is your Prisma schema file,
// learn more about it in the docs: https://pris.ly/d/prisma-schema

generator client {
  provider = "prisma-client-js"
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_URL")
}

model Item {
  userId String
  id String @id @default(uuid())
  title String
  src String @unique
  createdAt DateTime @default(now())
  updatedAt DateTime @updatedAt
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, it's time to setup Supabase to host our database. Go to &lt;a href="https://supabase.com/"&gt;Supabase&lt;/a&gt; and click on &lt;strong&gt;Start your project&lt;/strong&gt;. Then sign into it and create a new organization and then a new project. Go into the Supabase project settings and head over to Database. Then copy the URI.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--pCy-ouKe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p42yamifeh0h0kh19cvj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--pCy-ouKe--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_800/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/p42yamifeh0h0kh19cvj.png" alt="Image description" width="800" height="385"&gt;&lt;/a&gt;&lt;br&gt;
Paste the URI into .env file as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;DATABASE_URL=&amp;lt;Don't put quotes for this one&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;After that run the following commands:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;pnpm prisma migrate dev --name init
pnpm prisma db push
pnpm prisma generate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll soon be able to upload data into the database. But, we'll first need to copy the Anon Key in the API tab into our .env file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_SUPABASE_ANON="Put this inside quotes :)"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Also, create &lt;code&gt;db.ts&lt;/code&gt; in the root directory. This is to prevents problems when instantiating &lt;a href="https://www.prisma.io/docs/guides/other/troubleshooting-orm/help-articles/nextjs-prisma-client-dev-practices"&gt;Prisma client&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting Up Replicate
&lt;/h2&gt;

&lt;p&gt;In order to generate images using AI, we'll need to setup Replicate. Head over to &lt;a href="https://replicate.com/"&gt;Replicate&lt;/a&gt;, sign up ad get API tokens. Copy the token and paste it into your env file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;NEXT_PUBLIC_REPLICATE_API_KEY="Your API Key"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Generating Images
&lt;/h2&gt;

&lt;p&gt;To be able to generate images we'll set up api routes in the app directory. Create the following in the &lt;code&gt;app/api/generate/route.ts&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextResponse } from "next/server";
import { headers } from "next/headers";

// Create a new ratelimiter, that allows 5 requests per 24 hours

export async function POST(request: Request) {
  // Rate Limiter Code

  const { imageUrl, theme, room } = await request.json();

  // POST request to Replicate to start the image restoration generation process
  let startResponse = await fetch("https://api.replicate.com/v1/predictions", {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      Authorization: "Token " + process.env.REPLICATE_API_KEY,
    },
    body: JSON.stringify({
      version:
        "854e8727697a057c525cdb45ab037f64ecca770a1769cc52287c2e56472a247b",
      input: {
        image: imageUrl,
        prompt:
          "Make a " + room + ".The person want this in that room: " + theme,
        a_prompt:
          "best quality, extremely detailed, photo from Pinterest, interior, cinematic photo, ultra-detailed, ultra-realistic, award-winning, Room",
        n_prompt:
          "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
      },
    }),
  });

  let jsonStartResponse = await startResponse.json();

  let endpointUrl = jsonStartResponse.urls.get;

  // GET request to get the status of the image restoration process &amp;amp; return the result when it's ready
  let restoredImage: string | null = null;
  while (!restoredImage) {
    // Loop in 1s intervals until the alt text is ready
    console.log("Please wait...");
    let finalResponse = await fetch(endpointUrl, {
      method: "GET",
      headers: {
        "Content-Type": "application/json",
        Authorization: "Token " + process.env.REPLICATE_API_KEY,
      },
    });
    let jsonFinalResponse = await finalResponse.json();

    if (jsonFinalResponse.status === "succeeded") {
      restoredImage = jsonFinalResponse.output;
    } else if (jsonFinalResponse.status === "failed") {
      break;
    } else {
      await new Promise((resolve) =&amp;gt; setTimeout(resolve, 1000));
    }
  }

  return NextResponse.json(
    restoredImage ? restoredImage : "Failed to restore image"
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The above api will be called from the Form component, which will make a call to the Replicate API and get back a url containing AI generated image. Now, we need to make an API route to send the data to the Prisma database. We create &lt;code&gt;app/api/todo/route.ts&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { NextResponse } from "next/server";
import { cookies } from "next/headers";
import * as jose from "jose";
import { prisma } from "@/db";

export async function userId() {
  const token = cookies().get("hanko")?.value;
  const payload = jose.decodeJwt(token ?? "");
  return payload.sub;
}

export async function POST(req: Request) {
  const userID = await userId();
  const { src } = await req.json();
  const title = "abc";

  if (userID) {
    if (typeof title !== "string" || title.length === 0) {
      throw new Error("That can't be a title");
    }
    await prisma.item.create({
      data: { title, src, userId: userID ?? "" },
    });

    return NextResponse.json({ message: "Created Todo" }, { status: 200 });
  } else {
    return NextResponse.json({ error: "Not Found" }, { status: 404 });
  }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We're done with the backend. Now, our job is to make calls from the Form to store generate AI images and store them into the database. Modify the &lt;code&gt;components/Form.tsx&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"use client";
import Button from "@mui/material/Button";
import CloudUploadIcon from "@mui/icons-material/CloudUpload";
import { styled } from "@mui/material/styles";
import * as React from "react";
import TextField from "@mui/material/TextField";
import MenuItem from "@mui/material/MenuItem";
import { useRouter } from "next/navigation";
import { createClient } from "@supabase/supabase-js";
const VisuallyHiddenInput = styled("input")({
  clip: "rect(0 0 0 0)",
  clipPath: "inset(50%)",
  height: 1,
  overflow: "hidden",
  position: "absolute",
  bottom: 0,
  left: 0,
  whiteSpace: "nowrap",
  width: 1,
});
const currencies = [
  {
    value: "Living Room",
    label: "Living Room",
  },
  {
    value: "Store",
    label: "Store",
  },
  {
    value: "Bedroom",
    label: "Bedroom",
  },
  {
    value: "Bathroom",
    label: "Bathroom",
  },
  {
    value: "Office",
    label: "Office",
  },
  {
    value: "Kitchen",
    label: "Kitchen",
  },

  {
    value: "Balcony",
    label: "Balcony",
  },
];
export const Form = () =&amp;gt; {
  const supabase = createClient(
    "https://dgahpknmwckcozpfuyrp.supabase.co",
    process.env.NEXT_PUBLIC_SUPABASE_ANON!
  );
  const router = useRouter();
  const [loading, setLoading] = React.useState(false);
  const handleSubmit = async (
    file: File,
    name: string,
    value: string,
    valuee: string
  ) =&amp;gt; {
    setLoading(true);
    const { data, error } = await supabase.storage
      .from("Images")
      .upload("/" + file.name, file, { upsert: true });
    const publicUrl = supabase.storage
      .from("Images")
      .getPublicUrl("/" + data!.path);
    if (data) {
      console.log(publicUrl.data.publicUrl);
    } else {
      console.log(error);
    }
    const res = await fetch("/api/generate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        imageUrl: publicUrl.data.publicUrl,
        value,
        valuee,
      }),
    });

    let newPhoto = await res.json();
    if (res.status !== 200) {
      console.log(res);
    } else {
      console.log(newPhoto[1]);
    }
    setTimeout(() =&amp;gt; {
    }, 1300);
    await fetch(`/api/todo`, {
      method: "POST",
      credentials: "include",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        src: newPhoto[1],
      }),
    });
    router.refresh();
    setLoading(false);
  };
  const [file, setFile] = React.useState&amp;lt;File&amp;gt;();
  const [name, setName] = React.useState("Nothing");
  const [uploadUrl, setUploadUrl] = React.useState("");
  const [valuee, setValuee] = React.useState("Living Room");
  const [value, setValue] = React.useState("");
  return (
    &amp;lt;div className=" space-y-12 "&amp;gt;
      &amp;lt;div className="text-lg font-medium"&amp;gt;
        Upload an image and tell us what you want for your room.
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div className="space-y-4"&amp;gt;
          &amp;lt;Button
            component="label"
            variant="contained"
            startIcon={&amp;lt;CloudUploadIcon /&amp;gt;}
          &amp;gt;
            &amp;lt;div className="font-bold text-xl"&amp;gt;Upload file&amp;lt;/div&amp;gt;
            &amp;lt;VisuallyHiddenInput
              type="file"
              accept=".png"
              onChange={(e) =&amp;gt; {
                setName(e.target.files![0].name);
                setFile(e.target.files![0]);
              }}
            /&amp;gt;
          &amp;lt;/Button&amp;gt;
          &amp;lt;br&amp;gt;&amp;lt;/br&amp;gt;
          &amp;lt;div&amp;gt;{name} uploaded!&amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div className="text-white"&amp;gt;
          &amp;lt;TextField
            id="outlined-basic"
            label={&amp;lt;div style={{ color: "#1976D2" }}&amp;gt;Tell us more&amp;lt;/div&amp;gt;}
            variant="outlined"
            maxRows="3"
            multiline
            value={value}
            onChange={(e) =&amp;gt; {
              setValue(e.target.value);
            }}
            sx={{ width: "80%" }}
            inputProps={{ style: { color: "white" } }}
            focused
          /&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;div style={{ width: "100%" }}&amp;gt;
          &amp;lt;TextField
            id="outlined-select-currency"
            select
            label="Select Room Type"
            defaultValue="Living Room"
            value={valuee}
            helperText="Please select your currency"
            sx={{ width: "80%" }}
            focused
            SelectProps={{ style: { color: "white" } }}
            onChange={(e) =&amp;gt; {
              setValuee(e.target.value);
            }}
          &amp;gt;
            {currencies.map((option) =&amp;gt; (
              &amp;lt;MenuItem key={option.value} value={option.value}&amp;gt;
                {option.label}
              &amp;lt;/MenuItem&amp;gt;
            ))}
          &amp;lt;/TextField&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
      &amp;lt;div&amp;gt;
        &amp;lt;Button
          variant="contained"
          onClick={(e) =&amp;gt; {
            if (file != null) {
              {
                handleSubmit(file, name, value, valuee);
              }
            } else {
              window.alert("You need to upload an image");
            }
          }}
        &amp;gt;
          {!loading ? (
            &amp;lt;div className="font-bold text-xl"&amp;gt;RENDER DESIGNS&amp;lt;/div&amp;gt;
          ) : (
            &amp;lt;div className="font-bold text-xl"&amp;gt;PLEASE WAIT..&amp;lt;/div&amp;gt;
          )}
        &amp;lt;/Button&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/div&amp;gt;
  );
};

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We would also like to see the designs generated by the AI. We'll do it by modifying the &lt;code&gt;app/dashboard/page.tsx&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import { Logout } from "@/components/Logout";
import { Profile } from "@/components/Profile";
import { prisma } from "@/db";
import { userId } from "../api/todo/route";
import { Form } from "@/components/Form";
import Card from "@mui/material/Card";
import CardActions from "@mui/material/CardActions";
import CardMedia from "@mui/material/CardMedia";

export default async function Todo() {
  const userID = await userId();

  const items = await prisma.item.findMany({
    where: {
      userId: { equals: userID },
    },
  });
  return (
    &amp;lt;main className="bg-black text-white"&amp;gt;
      &amp;lt;div className="w-full flex py-8 px-12 space-x-6 justify-around"&amp;gt;
        &amp;lt;Profile /&amp;gt;
        &amp;lt;div className="font-bold sm:text-4xl text-2xl"&amp;gt;
          &amp;lt;a href="/"&amp;gt;HOMEDEC&amp;lt;/a&amp;gt;
        &amp;lt;/div&amp;gt;
        &amp;lt;Logout /&amp;gt;
      &amp;lt;/div&amp;gt;

      &amp;lt;div className="sm:grid grid-cols-3 gap-x-4 px-16 py-20"&amp;gt;
        &amp;lt;div className="col-span-1 pr-6 text-center"&amp;gt;
          &amp;lt;Form /&amp;gt;
        &amp;lt;/div&amp;gt;

        &amp;lt;div className="col-span-2 space-y-4"&amp;gt;
          &amp;lt;div className="text-3xl p-4 font-bold"&amp;gt;YOUR DESIGNS&amp;lt;/div&amp;gt;
          &amp;lt;div className="sm:grid grid-cols-2 space-y-4"&amp;gt;
            {items
              .slice(0)
              .reverse()
              .map((item) =&amp;gt; {
                return (
                  &amp;lt;div key={item.id}&amp;gt;
                    &amp;lt;Card sx={{ maxWidth: 345 }}&amp;gt;
                      &amp;lt;CardMedia
                        component="img"
                        alt={item.src}
                        image={item.src}
                      /&amp;gt;
                      &amp;lt;CardActions&amp;gt;
                        &amp;lt;a
                          href={item.src}
                          target="_blank"
                          className="text-green-600 font-semibold"
                        &amp;gt;
                          DOWNLOAD
                        &amp;lt;/a&amp;gt;
                      &amp;lt;/CardActions&amp;gt;
                    &amp;lt;/Card&amp;gt;
                  &amp;lt;/div&amp;gt;
                );
              })}
          &amp;lt;/div&amp;gt;
        &amp;lt;/div&amp;gt;
      &amp;lt;/div&amp;gt;
    &amp;lt;/main&amp;gt;
  );
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You might wonder why we've named one api route as todo. This project was built after understanding this &lt;a href="https://dev.to/hanko/building-a-nextjs-13-todo-app-with-prisma-and-passkey-authentication-by-hanko-4o8a"&gt;Todo app&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Update1:Enhancment Of The UI
&lt;/h2&gt;

&lt;p&gt;After checking the response of the users, I could identify a few ways to enhance the UI.&lt;/p&gt;

&lt;h3&gt;
  
  
  Adding an alert to let the user upload only an image.
&lt;/h3&gt;

&lt;p&gt;If you go to the &lt;code&gt;Form.tsx&lt;/code&gt; file under components directory, you'll find a Button MUI element. We are going to modify it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Button
          variant="contained"
          onClick={(e) =&amp;gt; {
            if (file != null &amp;amp;&amp;amp; file!.type.match("image.*")) {
//Handle submit is called only when the user uploads image
              {
                handleSubmit(file!, name, value, valuee);
              }
            } else {
//Else the user gets a window alert
              window.alert("You need to upload an image");
            }
          }}
        &amp;gt;
          {!loading ? (
            &amp;lt;div className="font-bold text-xl"&amp;gt;RENDER DESIGNS&amp;lt;/div&amp;gt;
          ) : (
            &amp;lt;div className="font-bold text-xl"&amp;gt;PLEASE WAIT..&amp;lt;/div&amp;gt;
          )}
&amp;lt;/Button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add a circular animation after the user clicks on Render Design
&lt;/h3&gt;

&lt;p&gt;This is just to make the UI look better. We'll finally end up with the following for the Button in the &lt;code&gt;Form.tsx&lt;/code&gt; file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;Button
          variant="contained"
          onClick={(e) =&amp;gt; {
            if (file != null &amp;amp;&amp;amp; file!.type.match("image.*")) {
              {
                handleSubmit(file!, name, value, valuee);
              }
            } else {
              window.alert("You need to upload an image");
            }
          }}
        &amp;gt;
          {!loading ? (
            &amp;lt;div className="font-bold text-xl"&amp;gt;RENDER DESIGNS&amp;lt;/div&amp;gt;
          ) : (
            &amp;lt;div className="font-bold text-xl flex justify-items-center"&amp;gt;
              PLEASE WAIT
              &amp;lt;CircularProgress color="secondary" /&amp;gt;
            &amp;lt;/div&amp;gt;
          )}
        &amp;lt;/Button&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Remember to import the CircularProgress element from MUI&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import CircularProgress from "@mui/material/CircularProgress";
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Alerting the user if there is no response from the API
&lt;/h3&gt;

&lt;p&gt;Currently, the project has been hosted for free on Replicate. So, due to resource limitations there could be no response from it. Hence, we are going to keep an alert for the same.&lt;br&gt;
In the &lt;code&gt;Form.tsx&lt;/code&gt; file, we'll modify the handleSubmit function.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const handleSubmit = async (
    file: File,
    name: string,
    value: string,
    valuee: string
  ) =&amp;gt; {
    setLoading(true);
    const { data, error } = await supabase.storage
      .from("Images")
      .upload("/" + file.name, file, { upsert: true });
    const publicUrl = supabase.storage
      .from("Images")
      .getPublicUrl("/" + data!.path);
    const res = await fetch("/api/generate", {
      method: "POST",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        imageUrl: publicUrl.data.publicUrl,
        value,
        valuee,
      }),
    });

    if (res.status !== 200) {
      setLoading(false);
      window.alert(
        "Sorry, our resources are busy currently. If the issue persists, please contact the owner"
      );
    }//This is the function to alert the user
    let newPhoto = await res.json();
    setTimeout(() =&amp;gt; {}, 1300);
    await fetch(`/api/todo`, {
      method: "POST",
      credentials: "include",
      headers: {
        "Content-Type": "application/json",
      },
      body: JSON.stringify({
        src: newPhoto[1],
      }),
    });
    router.refresh();
    setLoading(false);
  };
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Congratulations!!!
&lt;/h2&gt;

&lt;p&gt;The end result should look something like this one:&lt;br&gt;
&lt;a href="https://hanko-ai-app.vercel.app/"&gt;https://hanko-ai-app.vercel.app/&lt;/a&gt;&lt;br&gt;
Refer to this &lt;a href="https://github.com/Rajarshi-Misra/Hanko-AI-App"&gt;GitHub&lt;/a&gt; repo to understand the working of this project.&lt;br&gt;
Do leave a feedback. And, I'd be happy to colab for further projects.&lt;br&gt;
Thanks!&lt;/p&gt;

</description>
      <category>hanko</category>
      <category>ai</category>
      <category>webdev</category>
      <category>authentication</category>
    </item>
  </channel>
</rss>
