Skip to content

Commit 0f1a702

Browse files
committed
Add Navbar to Login and Register pages
1 parent 72b9c84 commit 0f1a702

File tree

10 files changed

+124
-118
lines changed

10 files changed

+124
-118
lines changed

frontend/src/api/user.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,8 @@ export const verifyToken = async (needsLogin: boolean) => {
5353
case 200:
5454
return true;
5555
case 401:
56-
// if (needsLogin) logout();
5756
return false;
5857
default:
59-
// if (needsLogin) logout();
6058
return false;
6159
}
6260
};
@@ -116,12 +114,7 @@ export const logout = () => {
116114
Cookie.remove("username");
117115
Cookie.remove("id");
118116
Cookie.remove("isAdmin");
119-
redirectToLogin().then(() => {
120-
toast.fire({
121-
icon: "success",
122-
title: "Logged out successfully",
123-
});
124-
});
117+
redirectToLogin();
125118
};
126119

127120
export const register = async (

frontend/src/app/(auth)/(user)/login/page.tsx

Lines changed: 43 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Input } from "@/components/ui/input";
77
import { zodResolver } from "@hookform/resolvers/zod";
88
import { useForm } from "react-hook-form";
99
import { z } from "zod";
10+
import Navbar from "../../home/components/navbar/Navbar";
1011

1112
const formSchema = z.object({
1213
email: z.string()
@@ -29,45 +30,48 @@ const Login = () => {
2930
};
3031

3132
return (
32-
<div className="max-w-xl mx-auto my-10 p-2">
33-
<h1 className="text-white font-extrabold text-h1">Login</h1>
34-
<p className="text-primary-300 text-lg">
35-
Login to our platform to access its features! Don&apos;t have an account? <a href="/register" className="text-yellow-500 hover:underline">Register here!</a>
36-
</p>
37-
<Form {...form}>
38-
<form className="my-10 grid gap-4" onSubmit={form.handleSubmit(onSubmit)}>
39-
<FormField
40-
control={form.control}
41-
name="email"
42-
render={({ field }) => (
43-
<FormItem>
44-
<FormLabel className="text-yellow-500 text-lg">EMAIL</FormLabel>
45-
<FormControl>
46-
<Input placeholder="email" {...field} className="focus:border-yellow-500 text-white"/>
47-
</FormControl>
48-
{/* <FormDescription>This is your public display name.</FormDescription> */}
49-
<FormMessage/>
50-
</FormItem>
51-
)}
52-
/>
53-
<FormField
54-
control={form.control}
55-
name="password"
56-
render={({ field }) => (
57-
<FormItem>
58-
<FormLabel className="text-yellow-500 text-lg">PASSWORD</FormLabel>
59-
<FormControl>
60-
<Input placeholder="password" type="password" {...field} className="focus:border-yellow-500 text-white"/>
61-
</FormControl>
62-
{/* <FormDescription>This is your public display name.</FormDescription> */}
63-
<FormMessage/>
64-
</FormItem>
65-
)}
66-
/>
67-
<Button type="submit" className="bg-yellow-500 hover:bg-yellow-300 px-4 py-2 my-2 rounded-md text-black">Login</Button>
68-
</form>
69-
</Form>
70-
</div>
33+
<>
34+
<Navbar/>
35+
<div className="max-w-xl mx-auto my-10 p-2">
36+
<h1 className="text-white font-extrabold text-h1">Login</h1>
37+
<p className="text-primary-300 text-lg">
38+
Login to our platform to access its features! Don&apos;t have an account? <a href="/register" className="text-yellow-500 hover:underline">Register here!</a>
39+
</p>
40+
<Form {...form}>
41+
<form className="my-10 grid gap-4" onSubmit={form.handleSubmit(onSubmit)}>
42+
<FormField
43+
control={form.control}
44+
name="email"
45+
render={({ field }) => (
46+
<FormItem>
47+
<FormLabel className="text-yellow-500 text-lg">EMAIL</FormLabel>
48+
<FormControl>
49+
<Input placeholder="email" {...field} className="focus:border-yellow-500 text-white"/>
50+
</FormControl>
51+
{/* <FormDescription>This is your public display name.</FormDescription> */}
52+
<FormMessage/>
53+
</FormItem>
54+
)}
55+
/>
56+
<FormField
57+
control={form.control}
58+
name="password"
59+
render={({ field }) => (
60+
<FormItem>
61+
<FormLabel className="text-yellow-500 text-lg">PASSWORD</FormLabel>
62+
<FormControl>
63+
<Input placeholder="password" type="password" {...field} className="focus:border-yellow-500 text-white"/>
64+
</FormControl>
65+
{/* <FormDescription>This is your public display name.</FormDescription> */}
66+
<FormMessage/>
67+
</FormItem>
68+
)}
69+
/>
70+
<Button type="submit" className="bg-yellow-500 hover:bg-yellow-300 px-4 py-2 my-2 rounded-md text-black">Login</Button>
71+
</form>
72+
</Form>
73+
</div>
74+
</>
7175
);
7276
};
7377

frontend/src/app/(auth)/(user)/register/page.tsx

Lines changed: 57 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { Input } from "@/components/ui/input";
77
import { zodResolver } from "@hookform/resolvers/zod";
88
import { useForm } from "react-hook-form";
99
import { z } from "zod";
10+
import Navbar from "../../home/components/navbar/Navbar";
1011

1112
const formSchema = z.object({
1213
username: z.string()
@@ -32,59 +33,62 @@ const Register = () => {
3233
};
3334

3435
return (
35-
<div className="max-w-xl mx-auto my-10 p-2">
36-
<h1 className="text-white font-extrabold text-h1">Register</h1>
37-
<p className="text-primary-300 text-lg">
38-
Register to our platform to access its features! Have an account? <a href="/login" className="text-yellow-500 hover:underline">Login here!</a>
39-
</p>
40-
<Form {...form}>
41-
<form className="my-10 grid gap-4" onSubmit={form.handleSubmit(onSubmit)}>
42-
<FormField
43-
control={form.control}
44-
name="username"
45-
render={({ field }) => (
46-
<FormItem>
47-
<FormLabel className="text-yellow-500 text-lg">USERNAME</FormLabel>
48-
<FormControl>
49-
<Input placeholder="username" {...field} className="focus:border-yellow-500 text-white"/>
50-
</FormControl>
51-
{/* <FormDescription>This is your public display name.</FormDescription> */}
52-
<FormMessage/>
53-
</FormItem>
54-
)}
55-
/>
56-
<FormField
57-
control={form.control}
58-
name="email"
59-
render={({ field }) => (
60-
<FormItem>
61-
<FormLabel className="text-yellow-500 text-lg">EMAIL</FormLabel>
62-
<FormControl>
63-
<Input placeholder="email" {...field} className="focus:border-yellow-500 text-white"/>
64-
</FormControl>
65-
{/* <FormDescription>This is your public display name.</FormDescription> */}
66-
<FormMessage/>
67-
</FormItem>
68-
)}
69-
/>
70-
<FormField
71-
control={form.control}
72-
name="password"
73-
render={({ field }) => (
74-
<FormItem>
75-
<FormLabel className="text-yellow-500 text-lg">PASSWORD</FormLabel>
76-
<FormControl>
77-
<Input placeholder="password" type="password" {...field} className="focus:border-yellow-500 text-white"/>
78-
</FormControl>
79-
{/* <FormDescription>This is your public display name.</FormDescription> */}
80-
<FormMessage/>
81-
</FormItem>
82-
)}
83-
/>
84-
<Button type="submit" className="bg-yellow-500 hover:bg-yellow-300 px-4 py-2 my-2 rounded-md text-black">Login</Button>
85-
</form>
86-
</Form>
87-
</div>
36+
<>
37+
<Navbar/>
38+
<div className="max-w-xl mx-auto my-10 p-2">
39+
<h1 className="text-white font-extrabold text-h1">Register</h1>
40+
<p className="text-primary-300 text-lg">
41+
Register to our platform to access its features! Have an account? <a href="/login" className="text-yellow-500 hover:underline">Login here!</a>
42+
</p>
43+
<Form {...form}>
44+
<form className="my-10 grid gap-4" onSubmit={form.handleSubmit(onSubmit)}>
45+
<FormField
46+
control={form.control}
47+
name="username"
48+
render={({ field }) => (
49+
<FormItem>
50+
<FormLabel className="text-yellow-500 text-lg">USERNAME</FormLabel>
51+
<FormControl>
52+
<Input placeholder="username" {...field} className="focus:border-yellow-500 text-white"/>
53+
</FormControl>
54+
{/* <FormDescription>This is your public display name.</FormDescription> */}
55+
<FormMessage/>
56+
</FormItem>
57+
)}
58+
/>
59+
<FormField
60+
control={form.control}
61+
name="email"
62+
render={({ field }) => (
63+
<FormItem>
64+
<FormLabel className="text-yellow-500 text-lg">EMAIL</FormLabel>
65+
<FormControl>
66+
<Input placeholder="email" {...field} className="focus:border-yellow-500 text-white"/>
67+
</FormControl>
68+
{/* <FormDescription>This is your public display name.</FormDescription> */}
69+
<FormMessage/>
70+
</FormItem>
71+
)}
72+
/>
73+
<FormField
74+
control={form.control}
75+
name="password"
76+
render={({ field }) => (
77+
<FormItem>
78+
<FormLabel className="text-yellow-500 text-lg">PASSWORD</FormLabel>
79+
<FormControl>
80+
<Input placeholder="password" type="password" {...field} className="focus:border-yellow-500 text-white"/>
81+
</FormControl>
82+
{/* <FormDescription>This is your public display name.</FormDescription> */}
83+
<FormMessage/>
84+
</FormItem>
85+
)}
86+
/>
87+
<Button type="submit" className="bg-yellow-500 hover:bg-yellow-300 px-4 py-2 my-2 rounded-md text-black">Login</Button>
88+
</form>
89+
</Form>
90+
</div>
91+
</>
8892
);
8993
};
9094

File renamed without changes.
File renamed without changes.

frontend/src/app/(home)/components/landing-page/LandingPage.tsx renamed to frontend/src/app/(auth)/home/components/landing-page/LandingPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import CodeSnippet from "@/app/(home)/components/code-snippet/CodeSnippetHighlight";
1+
import CodeSnippet from "@/app/(auth)/home/components/code-snippet/CodeSnippetHighlight";
22
import { Button } from "@/components/ui/button";
33
import { Card, CardContent } from "@/components/ui/card";
44
import { useRouter } from "next/navigation";
File renamed without changes.

frontend/src/app/(auth)/leetcode-dashboard/page.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { AuthStatus, useAuth } from "@/components/auth/AuthContext";
44
import { useState, useEffect } from "react";
5-
import LandingPage from "@/app/(home)/components/landing-page/LandingPage";
5+
import LandingPage from "@/app/(auth)/home/components/landing-page/LandingPage";
66
import LeetcodeDashboard from "./LeetcodeDashboard";
77
import { getToken } from "@/api/user";
88

@@ -13,8 +13,10 @@ const LeetcodeDashboardPage = () => {
1313

1414
// Simulate token fetching or resolving logic
1515
useEffect(() => {
16-
if (token !== undefined) {
16+
if (!!token) {
1717
setLoading(false);
18+
} else {
19+
window.location.href = "/login";
1820
}
1921
}, [token]);
2022

frontend/src/app/(auth)/page.tsx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
"use client";
2+
3+
import Navbar from "@/app/(auth)/home/components/navbar/Navbar";
4+
import LandingPage from "@/app/(auth)/home/components/landing-page/LandingPage";
5+
import { getToken } from "@/api/user";
6+
import AuthDashboard from "./components/dashboard/Dashboard";
7+
8+
const Home = () => {
9+
const token = getToken();
10+
return (
11+
!!token ? <AuthDashboard/> : <>
12+
<Navbar />
13+
<LandingPage />
14+
</>
15+
);
16+
};
17+
18+
export default Home;

frontend/src/app/(home)/page.tsx

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)