Skip to content

Commit f7d178c

Browse files
committed
login signup setup typesight
1 parent 21c6811 commit f7d178c

File tree

15 files changed

+188
-60
lines changed

15 files changed

+188
-60
lines changed

package-lock.json

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

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
"@radix-ui/react-label": "^2.0.2",
1717
"@radix-ui/react-slot": "^1.0.2",
1818
"@reduxjs/toolkit": "^2.2.2",
19-
"@types/jest": "^29.5.12",
2019
"axios": "^1.6.8",
2120
"class-variance-authority": "^0.7.0",
2221
"clsx": "^2.1.0",
2322
"jest-environment-jsdom": "^29.6.2",
23+
"js-cookie": "^3.0.5",
2424
"lucide-react": "^0.350.0",
2525
"react": "^18.2.0",
2626
"react-dom": "^18.2.0",
@@ -33,6 +33,7 @@
3333
"zod": "^3.22.4"
3434
},
3535
"devDependencies": {
36+
"@types/js-cookie": "^3.0.6",
3637
"@types/node": "^20.11.25",
3738
"@types/react": "^18.2.15",
3839
"@types/react-dom": "^18.2.7",

src/App.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,17 @@
1-
import React from "react";
1+
import React, { useEffect } from "react";
22
import "./App.css";
33
import Navbar from "./components/Navbar";
44
import { Outlet } from "react-router-dom";
55
import ContentWrapper from "./components/ContentWrapper";
66
import Footer from "./components/Footer";
7+
import { useDispatch } from "react-redux";
8+
import { getUserInfo } from "./redux-store/slices/authSlice";
9+
import { AppDispatch } from "./redux-store/store";
710
function App() {
11+
const dispatch:AppDispatch=useDispatch();
12+
useEffect(()=>{
13+
dispatch(getUserInfo())
14+
},[dispatch])
815
return (
916
<div className="min-h-screen w-full ">
1017
<Navbar />

src/api/axiosclient.ts

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,46 @@
1+
/* eslint-disable @typescript-eslint/no-explicit-any */
12
import { LoginData, ResultData, SingupData } from '@/types';
23
import axios from 'axios';
4+
import Cookies from 'js-cookie';
35
class AxiosClient {
4-
client;
6+
private client;
57
constructor() {
68
this.client = axios.create({
7-
baseURL: String(process.env.VITE_APP_BACKEND_BASE_URL),
9+
baseURL: String(import.meta.env.VITE_APP_BACKEND_BASE_URL),
810
withCredentials: true,
911
headers: {
10-
'Content-Type': ['application/json', 'application/x-www-form-urlencoded'],
12+
'Content-Type': 'application/json',
13+
'Access-Control-Allow-Origin': String(import.meta.env.VITE_APP_FRONTEND_BASE_URL),
14+
"Access-Control-Allow-Methods": "GET,PUT,POST,DELETE,PATCH,OPTIONS",
15+
'cache-control': 'private',
16+
'E-Tag': Cookies.get('auth_token'),
1117
},
1218
});
1319
}
14-
async post(url: string, content: SingupData | LoginData | ResultData) {
15-
try{
16-
const {data}=await this.client.post(url, content);
17-
return data;
18-
}catch(e){
19-
return e;
20-
}
20+
async post(url: string, content: LoginData | SingupData | ResultData) {
21+
try {
22+
const { data } = await this.client.post(url, content);
23+
return data;
24+
} catch (e: any) {
25+
if (import.meta.env.VITE_APP_ENV === "development") console.log(e.response.data);
26+
return e;
27+
}
2128
}
2229
async get(url: string) {
23-
try{
24-
const {data}=await this.client.get(url);
30+
try {
31+
const { data } = await this.client.get(url);
2532
return data;
26-
}catch(e){
33+
} catch (e: any) {
34+
if (import.meta.env.VITE_APP_ENV === "development") console.log(e.response.data);
2735
return e;
2836
}
2937
}
30-
async patch(url:string){
31-
try{
32-
const {data}=await this.client.patch(url);
38+
async patch(url: string) {
39+
try {
40+
const { data } = await this.client.patch(url);
3341
return data;
34-
}catch(e){
42+
} catch (e: any) {
43+
if (import.meta.env.VITE_APP_ENV === "development") console.log(e.response.data);
3544
return e;
3645
}
3746
}

src/components/Navbar.tsx

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@ import {
88
DropdownMenuTrigger,
99
} from "@/components/ui/dropdown-menu";
1010
import { Menu } from "lucide-react";
11+
import { useAuthStatus } from "@/hooks/useAuthStatus";
12+
import { useNavigate } from "react-router-dom";
1113

1214
const routes = [
1315
{ name: "Services", path: "#about", id: 1 },
1416
{ name: "About", path: "#about", id: 2 },
1517
{ name: "Contact", path: "#contact", id: 3 },
1618
];
17-
const Navbar:React.FC = () => {
19+
const Navbar: React.FC = () => {
20+
const { status, user } = useAuthStatus();
21+
const navigate = useNavigate();
1822
return (
1923
<nav className="flex justify-between items-center py-4 px-8 border-b">
2024
<div className="flex items-center space-x-4">
@@ -58,7 +62,14 @@ const Navbar:React.FC = () => {
5862
</DropdownMenuContent>
5963
</DropdownMenu>
6064
</div>
61-
<Button className="bg-blue-600 text-white">Sign Up</Button>
65+
<Button
66+
className="bg-blue-600 text-white"
67+
onClick={() => {
68+
status ? navigate(`/dashboard/${user?.id}`) : navigate("/signup");
69+
}}
70+
>
71+
{status ? "DashBoard" : "Join"}
72+
</Button>
6273
</div>
6374
</nav>
6475
);

src/components/Protected.tsx

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,27 @@
11
import React, { useEffect, useState } from "react";
2-
import { useSelector } from "react-redux";
3-
import { AuthState } from "@/redux-store/store";
42
import { useNavigate } from "react-router-dom";
3+
import { useAuthStatus } from "@/hooks/useAuthStatus";
54
interface Props {
65
children: React.ReactNode;
76
authentication: boolean;
87
}
98
const Protected = ({ children, authentication }: Props) => {
10-
const authStatus = useSelector((state: AuthState) => state.auth.status);
11-
const isEmailVerified=true; //dummy value for test;
9+
const { status, user } = useAuthStatus();
1210
const navigate = useNavigate();
1311
const [loading, setloading] = useState<boolean>(true);
1412
useEffect(() => {
15-
if (authentication && authStatus != true) {
13+
if (authentication && status != true) {
1614
navigate("/login");
1715
}
18-
if(authStatus && authentication && !isEmailVerified){
19-
navigate("/verify");
16+
if (status && authentication) {
17+
if (!user?.isEmailVerified) navigate("/verify");
2018
}
21-
if(authStatus && authentication && isEmailVerified){
22-
navigate("/test");
23-
}
24-
if (!authentication && authStatus === true) {
19+
if (!authentication && status === true) {
2520
navigate("/test");
2621
}
2722
setloading(false);
28-
}, [authStatus, authentication, navigate,isEmailVerified]);
23+
}, [status, authentication, navigate, user?.isEmailVerified]);
2924
return loading ? null : <>{children}</>;
3025
};
3126

32-
export default Protected;
27+
export default Protected;

src/hooks/useAppDispatch.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { AppDispatch } from "@/redux-store/store"
2+
import { useDispatch } from "react-redux"
3+
4+
const useAppDispatch = () => {
5+
const dispatch = useDispatch<AppDispatch>();
6+
return dispatch;
7+
}
8+
export default useAppDispatch;

src/hooks/useAuthStatus.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { AuthState } from "@/redux-store/store"
22
import { useSelector } from "react-redux"
33

44
const useAuthStatus = () => {
5-
const authStatus=useSelector((state: AuthState) => state.auth.status);
6-
return [authStatus];
5+
const { status, user } = useSelector((state: AuthState) => state.auth);
6+
return { status, user };
77
}
8-
export { useAuthStatus};
8+
export { useAuthStatus };

src/pages/EmailVerification/EmailVerification.tsx

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { Label } from "@/components/ui/label"
2-
import { Input } from "@/components/ui/input"
3-
import { Button } from "@/components/ui/button"
1+
import { Label } from "@/components/ui/label";
2+
import { Input } from "@/components/ui/input";
3+
import { Button } from "@/components/ui/button";
44

55
export default function Component() {
66
return (
@@ -27,6 +27,5 @@ export default function Component() {
2727
</Button>
2828
</div>
2929
</div>
30-
)
30+
);
3131
}
32-

src/pages/Homepage/HomeScreen.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import about from "../../assets/images/about.png";
55
import CheckCircleIcon from "@/icons/Checkicon";
66
import ContactUS from "@/components/ContactUS";
77
import Pricing from "@/components/Pricing";
8+
import { ArrowRightIcon } from "lucide-react";
9+
import { useNavigate } from "react-router-dom";
810
const HomeScreen = () => {
11+
const navigate = useNavigate();
912
return (
1013
<>
1114
{/* Banner */}
@@ -19,7 +22,12 @@ const HomeScreen = () => {
1922
accuracy tests. Whether you’re a professional typist or just looking
2023
to improve your skills, we’ve got you covered.
2124
</p>
22-
<Button className="bg-blue-600 text-white">View All Services</Button>
25+
<Button
26+
className="bg-blue-600 text-white"
27+
onClick={() => navigate("/login")}
28+
>
29+
Explore now <ArrowRightIcon />
30+
</Button>
2331
</div>
2432
<img
2533
alt="Typing illustration"

0 commit comments

Comments
 (0)