Skip to content

Commit 17cd4bd

Browse files
committed
basic auth ui setup with protected routing
1 parent 449c508 commit 17cd4bd

File tree

15 files changed

+466
-13
lines changed

15 files changed

+466
-13
lines changed

package-lock.json

Lines changed: 120 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,17 @@
1313
"dependencies": {
1414
"@radix-ui/react-dropdown-menu": "^2.0.6",
1515
"@radix-ui/react-icons": "^1.3.0",
16+
"@radix-ui/react-label": "^2.0.2",
1617
"@radix-ui/react-slot": "^1.0.2",
18+
"@reduxjs/toolkit": "^2.2.2",
1719
"@types/jest": "^29.5.12",
1820
"class-variance-authority": "^0.7.0",
1921
"clsx": "^2.1.0",
2022
"jest-environment-jsdom": "^29.6.2",
2123
"lucide-react": "^0.350.0",
2224
"react": "^18.2.0",
2325
"react-dom": "^18.2.0",
26+
"react-redux": "^9.1.0",
2427
"react-router-dom": "^6.22.3",
2528
"tailwind-merge": "^2.2.1",
2629
"tailwindcss-animate": "^1.0.7",

src/approutes.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { createBrowserRouter } from 'react-router-dom';
22
import App from './App';
33
import HomeScreen from './pages/Homepage/HomeScreen';
4+
import SignupScreen from './pages/SignupScreen/SignupScreen';
5+
import LoginScreen from './pages/LoginScreen/LoginScreen';
6+
import EmailVerification from './pages/EmailVerification/EmailVerification';
7+
import Protected from './components/Protected';
48
const router = createBrowserRouter([
59
{
610
path: "/",
@@ -10,6 +14,17 @@ const router = createBrowserRouter([
1014
path: "/",
1115
element: <HomeScreen />,
1216
},
17+
{
18+
path: "/signup",
19+
element:<Protected authentication={false}><SignupScreen /></Protected>,
20+
},{
21+
path: "/login",
22+
element: <Protected authentication={false}><LoginScreen /></Protected>,
23+
},
24+
{
25+
path: "/verify",
26+
element: <Protected authentication={true}><EmailVerification /></Protected>,
27+
}
1328
],
1429
},
1530
]);

src/components/Pricing.tsx

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
import { Button } from "@/components/ui/button";
2+
import { SVGProps } from "react";
3+
4+
export default function Pricing() {
5+
return (
6+
<section className="w-full py-12 bg-gradient-to-r from-gray-50 to-gray-100 dark:from-zinc-900 dark:to-zinc-800 flex items-center justify-center">
7+
<div className="relative flex flex-col p-6 bg-white shadow-lg rounded-lg dark:bg-zinc-850 justify-between border border-purple-500">
8+
<div className="px-3 py-1 text-sm text-white bg-gradient-to-r from-pink-500 to-purple-500 rounded-full inline-block absolute top-0 left-1/2 transform -translate-x-1/2 -translate-y-1/2">
9+
Popular
10+
</div>
11+
<div>
12+
<h3 className="text-2xl font-bold text-center">Pro</h3>
13+
<div className="mt-4 text-center text-zinc-600 dark:text-zinc-400">
14+
<span className="text-4xl font-bold">$59</span>/ month
15+
</div>
16+
<ul className="mt-4 space-y-2">
17+
<li className="flex items-center dark:text-black">
18+
<CheckIcon className="text-white text-2xs bg-green-500 rounded-full mr-2 p-1 " />
19+
100 daily Limit
20+
</li>
21+
<li className="flex items-center dark:text-black">
22+
<CheckIcon className="text-white text-xs bg-green-500 rounded-full mr-2 p-1" />
23+
Unlimited Usage
24+
</li>
25+
<li className="flex items-center dark:text-black">
26+
<CheckIcon className="text-white text-xs bg-green-500 rounded-full mr-2 p-1" />
27+
24/7 Support
28+
</li>
29+
</ul>
30+
</div>
31+
<div className="mt-6">
32+
<Button className="w-full bg-gradient-to-r from-pink-500 to-purple-500">
33+
Get Started
34+
</Button>
35+
</div>
36+
</div>
37+
</section>
38+
);
39+
}
40+
41+
function CheckIcon(props: JSX.IntrinsicAttributes & SVGProps<SVGSVGElement>) {
42+
return (
43+
<svg
44+
{...props}
45+
xmlns="http://www.w3.org/2000/svg"
46+
width="24"
47+
height="24"
48+
viewBox="0 0 24 24"
49+
fill="none"
50+
stroke="currentColor"
51+
strokeWidth="2"
52+
strokeLinecap="round"
53+
strokeLinejoin="round"
54+
>
55+
<polyline points="20 6 9 17 4 12" />
56+
</svg>
57+
);
58+
}

src/components/Protected.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import React, { useEffect, useState } from "react";
2+
import { useSelector } from "react-redux";
3+
import { AuthState } from "@/redux-store/store";
4+
import { useNavigate } from "react-router-dom";
5+
interface Props {
6+
children: React.ReactNode;
7+
authentication: boolean;
8+
}
9+
const Protected = ({ children, authentication }: Props) => {
10+
const authStatus = useSelector((state: AuthState) => state.auth.status);
11+
const navigate = useNavigate();
12+
const [loading, setloading] = useState<boolean>(true);
13+
useEffect(() => {
14+
if (authentication && authStatus != true) {
15+
navigate("/login");
16+
}
17+
if (!authentication && authStatus === true) {
18+
navigate("/");
19+
}
20+
setloading(false);
21+
}, [authStatus, authentication, navigate]);
22+
return loading ? null : <>{children}</>;
23+
};
24+
25+
export default Protected;

src/components/ui/input.tsx

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import * as React from "react"
2+
3+
import { cn } from "@/lib/utils"
4+
5+
export interface InputProps
6+
extends React.InputHTMLAttributes<HTMLInputElement> {}
7+
8+
const Input = React.forwardRef<HTMLInputElement, InputProps>(
9+
({ className, type, ...props }, ref) => {
10+
return (
11+
<input
12+
type={type}
13+
className={cn(
14+
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50",
15+
className
16+
)}
17+
ref={ref}
18+
{...props}
19+
/>
20+
)
21+
}
22+
)
23+
Input.displayName = "Input"
24+
25+
export { Input }

0 commit comments

Comments
 (0)