Skip to content

Commit

Permalink
Merge pull request #55 from Bug-Bust3rs/dev
Browse files Browse the repository at this point in the history
feat : backend connect
  • Loading branch information
Puskar-Roy authored Jul 22, 2024
2 parents 146af6c + 8541eb8 commit d86a99f
Show file tree
Hide file tree
Showing 19 changed files with 461 additions and 116 deletions.
2 changes: 1 addition & 1 deletion apps/backend/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const app: Express = express();

app.use(express.json());
app.use(morgan("dev"));
// app.use(config.DEV_ENV === "PROD" ? cors(corsOptions) : cors());
app.use(config.DEV_ENV === "PROD" ? cors(corsOptions) : cors());
app.use(limiter);

app.use("/api/v0.1/auth", authRoutes);
Expand Down
3 changes: 3 additions & 0 deletions apps/backend/src/interfaces/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,6 @@ export interface User {
location: string;
password: string;
}



2 changes: 1 addition & 1 deletion apps/backend/src/lib/corsConfig.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { CorsOptions } from "cors";
const whitelist = ["http://localhost:5173","https://caree.vercel.app"];
const whitelist = ["http://localhost:5173","https://www.myhackathon.xyz"];

const corsOptions: CorsOptions = {
origin: function (origin, callback) {
Expand Down
1 change: 1 addition & 0 deletions apps/frontend/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

.env
node_modules
dist
dist-ssr
Expand Down
2 changes: 1 addition & 1 deletion apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
"preview": "vite preview"
},
"dependencies": {

"@tabler/icons-react": "^3.11.0",
"aos": "^2.3.4",
"axios": "^1.7.2",
"clsx": "^2.1.1",
"framer-motion": "^11.3.6",
"react": "^18.2.0",
Expand Down
36 changes: 22 additions & 14 deletions apps/frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Route, Routes } from "react-router-dom";
import { Route, Routes, Navigate } from "react-router-dom";
import Home from "./components/homepage/Home";
import Navbar from "./components/Navbar";
import Login from "./components/auth/Login";
Expand All @@ -7,25 +7,33 @@ import Register from "./components/auth/Register";
import ForgotPassword from "./components/auth/Forgot-Password";
import OTP from "./components/auth/OTP";
import { ThemeProvider } from "./context/ThemeCOntext";

import Footer from "./components/Footer";
import Contact from "./components/Contact";
import { useAuthContext } from "./hooks/useAuthContext";

function App() {

const { state } = useAuthContext();
console.log(state);

return (
<>
<ThemeProvider>
<Navbar />
<Routes>
<Route path="/" element={<Home />} />
<Route path="/login" element={<Login />} />
<Route path="/register" element={<Register />} />
<Route path="/profile" element={<ProfileSetup />} />
<Route path="/forgot-password" element={<ForgotPassword />} />
<Route path="/otp" element={<OTP />} />
<Route path="/contact" element={<Contact/>}/>
</Routes>
</ThemeProvider>
<Footer />

<ThemeProvider>
<Navbar />
<Routes>
<Route path="/" element={state.user ? <Home /> : <Navigate to="/login" />} />
<Route path="/login" element={!state.user ? <Login /> : <Navigate to="/" />} />
<Route path="/register" element={!state.user ? <Register /> : <Navigate to="/" />} />
<Route path="/profile" element={state.user ? <ProfileSetup /> : <Navigate to="/login" />} />
<Route path="/forgot-password" element={<ForgotPassword />} />
<Route path="/otp/:userId" element={<OTP />} />
<Route path="/contact" element={state.user ? <Contact /> : <Navigate to="/login" />} />
</Routes>
</ThemeProvider>
<Footer />

</>
);
}
Expand Down
58 changes: 45 additions & 13 deletions apps/frontend/src/components/auth/Login.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { useState } from "react";
import log_img from "../../assets/login-animate.svg";
import { Link } from "react-router-dom";
import { useLogin } from "../../hooks/useLogin";

export default function Login(): JSX.Element {
const [email, setEmail] = useState<string>("");
const [password, setPassword] = useState<string>("");
const { login, error, isLoading, isSucess } = useLogin();

const handleEmailChange = (event: React.ChangeEvent<HTMLInputElement>) => {
setEmail(event.target.value);
Expand All @@ -16,6 +18,11 @@ export default function Login(): JSX.Element {

const handleClick = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const loginData = {
email,
password,
};
await login(loginData);
};

return (
Expand All @@ -26,45 +33,70 @@ export default function Login(): JSX.Element {
</div>
<div className="p-5 flex flex-col justify-around">
<form onSubmit={handleClick}>
<h1 className="text-4xl ml-[40px] font-medium mb-8 dark:text-white">Welcome<span className="text-blue-400"> Back!</span></h1>
<h1 className="text-4xl ml-[40px] font-medium mb-8 dark:text-white">
Welcome <span className="text-blue-400">Back!</span>
</h1>
<div>
<label className="poppins-medium ml-1 text-slate-600 dark:text-slate-300">Email Address</label>
<label htmlFor="email" className="poppins-medium ml-1 text-slate-600 dark:text-slate-300">
Email Address
</label>
<input
id="email"
className="border px-3 py-2 w-[350px] rounded-xl bg-slate-100 dark:bg-slate-600 mt-3 dark:border-slate-600"
type="text"
type="email"
placeholder="[email protected]"
value={email}
onChange={handleEmailChange}
required
/>
</div>
<div className="mt-3">
<label className="poppins-medium ml-1 text-slate-600 dark:text-slate-300">Enter Password</label>
<label htmlFor="password" className="poppins-medium ml-1 text-slate-600 dark:text-slate-300">
Enter Password
</label>
<input
id="password"
className="border px-3 py-2 w-[350px] rounded-xl bg-slate-100 dark:bg-slate-600 mt-3 dark:border-slate-600"
type="password"
placeholder="Your Password"
value={password}
onChange={handlePasswordChange}
required
/>
</div>
<div className="ml-56">
<button className="mt-3 font-normal text-base text-blue-500"><Link to='/forgot-password'>Forgot Password?</Link></button>
<div className="ml-56 mt-3">
<button className="font-normal text-base text-blue-500">
<Link to='/forgot-password'>Forgot Password?</Link>
</button>
</div>
<button
type="submit"
disabled={isLoading}
className="ml-14 mt-3 w-[230px] active:scale-[.98] active:duration-75 hover:scale-[1.01] ease-in-out transition-all p-2.5 rounded-3xl bg-gradient-to-r from-blue-700 to-blue-500 text-white text-lg font-semibold poppins-extrabold"
key="1"
>
<p>Log in</p>
{isLoading ? "Logging in..." : "Log in"}
</button>
<div className="mt-6 flex ml-[50px]">
<p className="font-medium text-base dark:text-slate-300">Did not have an Account?</p>
<button className="text-blue-500 text-base font-normal ml-2">
<Link to="/register">Register</Link>
</button>
<p className="font-medium text-base dark:text-slate-300">Don't have an Account?</p>
<Link to="/register">
<button className="text-blue-500 text-base font-normal ml-2">
Register
</button>
</Link>
</div>
</form>
{error && (
<div className="bg-rose-200 text-rose-500 p-5 rounded-lg mt-4">
{error}
</div>
)}
{isSucess && (
<div className="bg-green-200 text-green-500 p-5 rounded-lg mt-4">
Successfully logged in!
</div>
)}
</div>
</div>
</main>
);
}
}
123 changes: 76 additions & 47 deletions apps/frontend/src/components/auth/OTP.tsx
Original file line number Diff line number Diff line change
@@ -1,74 +1,103 @@
import { useState, useRef } from 'react';
import log_img from '../../assets/enter-otp-animate.svg';
import { useVerifyLogin } from '../../hooks/useLoginVerify';
import { useParams } from 'react-router-dom';

export default function OTP() {
const { verify, error, isLoading, isSucess } = useVerifyLogin();
const [otp, setOtp] = useState<string[]>(Array(6).fill(""));
let { userId } = useParams();


const inputRefs = useRef<(HTMLInputElement | null)[]>([]);

const handleChange = (event: React.ChangeEvent<HTMLInputElement>, index: number) => {
const value = event.target.value;
if (/^\d*$/.test(value) && value.length <= 1) {
const newOtp = [...otp];
newOtp[index] = value;
setOtp(newOtp);


if (value && index < otp.length - 1) {
inputRefs.current[index + 1]?.focus();
}
}
};

const handleKeyDown = (event: React.KeyboardEvent<HTMLInputElement>, index: number) => {
if (event.key === 'Backspace' && !otp[index] && index > 0) {
inputRefs.current[index - 1]?.focus();
}
};

const handleVerify = async () => {
// Your verification logic here
console.log('OTP:', otp.join(''));
const verifydata = { email:userId, otp: otp.join('') };
await verify(verifydata);
};

return (
<div className="w-full h-screen flex flex-col dark:bg-slate-800">
<div className="w-full h-screen flex flex-col bg-[url('https://pagedone.io/asset/uploads/1691055810.png')] dark:bg-slate-900 bg-center bg-cover">
<div className="grid grid-cols-1 md:grid-cols-2 m-auto h-[350px] sm:max-w-[800px] rounded-2xl">
<div className="w-full h-[350px] hidden md:block">
<img className="w-full h-[100%]" src={log_img} alt="OTP" />
</div>
<div className="p-4 flex flex-col justify-around">
<h2 className="text-4xl font-medium poppins-medium text-center mb-4 dark:text-white">
<h2 className="text-4xl font-medium poppins-medium text-center mb-4 mr-4 dark:text-white">
Enter Your <span className="text-blue-500">OTP</span>
</h2>
<p className="justify-center items-center dark:text-gray-300">
Enter the one-time password (OTP) sent to your registered <br /> email address to verify your identity and
<p className="justify-center items-center dark:text-gray-300 mb-4">
Enter the OTP sent to your registered email address to verify your identity and
continue.
</p>
<div className="flex flex-col space-y-12">
<div className="flex flex-row items-center justify-between mx-auto w-full max-w-[27rem]">
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
<div className="w-12 h-14">
<input
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
/>
</div>
{otp.map((digit, index) => (
<div key={index} className="w-12 h-14">
<input
ref={(el) => (inputRefs.current[index] = el)}
className="w-full h-full flex flex-col items-center justify-center text-center px-4 outline-none rounded-xl border border-gray-600 text-lg bg-white focus:bg-gray-50 focus:ring-1 focus:border-none ring-blue-500 dark:bg-slate-600 dark:text-white dark:focus:bg-slate-500"
type="text"
maxLength={1}
value={digit}
onChange={(e) => handleChange(e, index)}
onKeyDown={(e) => handleKeyDown(e, index)}
/>
</div>
))}
</div>
</div>
<div className="mt-7">
<button

onClick={handleVerify}
disabled={isLoading}
className="ml-[110px] flex flex-row items-center justify-center text-center w-[200px] border rounded-3xl hover:bg-cyan-400 outline-none py-3 bg-cyan-500 border-none text-white shadow-sm text-base font-semibold poppins-extrabold"

>
<p>Verify Account</p>
{isLoading ?<p>Verifying..</p>: <p>Verify Account</p>}
</button>
</div>
<div className="mt-7">
<button
className=" flex flex-row items-center justify-center text-center w-full border rounded-3xl py-3 bg-white border-black text-black shadow-sm text-base font-semibold poppins-extrabold"
>
<p>Resend OTP</p>
</button>
</div>
</div>
{error && (
<div className="bg-rose-200 text-rose-500 p-5 rounded-lg mt-4">
{error}
</div>
)}
{isSucess && (
<div className="bg-green-200 text-green-500 p-5 rounded-lg mt-4">
Successfully logged in!
</div>
)}
</div>
</div>
);
Expand Down
Loading

0 comments on commit d86a99f

Please sign in to comment.