Spaces:
Running
Running
ChandimaPrabath
commited on
Commit
·
7afbbc5
1
Parent(s):
e71a2ef
v0.0.1
Browse files- frontend/app/components/NexusAuth.css +76 -0
- frontend/app/components/NexusAuth.js +90 -0
- frontend/app/globals.css +30 -14
- frontend/app/layout.js +3 -5
- frontend/app/lib/Nexus_Auth_API.js +66 -0
frontend/app/components/NexusAuth.css
ADDED
@@ -0,0 +1,76 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
.nexus-auth-form {
|
2 |
+
max-width: 400px;
|
3 |
+
margin: 0 auto;
|
4 |
+
padding: 20px;
|
5 |
+
border: 1px solid var(--primary);
|
6 |
+
border-radius: 5px;
|
7 |
+
background-color: var(--accent);
|
8 |
+
}
|
9 |
+
|
10 |
+
.nexus-auth-form h2 {
|
11 |
+
text-align: center;
|
12 |
+
margin-bottom: 20px;
|
13 |
+
color: var(--foreground);
|
14 |
+
}
|
15 |
+
|
16 |
+
.form-group {
|
17 |
+
margin-bottom: 15px;
|
18 |
+
}
|
19 |
+
|
20 |
+
.form-group label {
|
21 |
+
display: block;
|
22 |
+
margin-bottom: 5px;
|
23 |
+
color: var(--foreground);
|
24 |
+
}
|
25 |
+
|
26 |
+
.form-group input {
|
27 |
+
width: 100%;
|
28 |
+
padding: 8px;
|
29 |
+
box-sizing: border-box;
|
30 |
+
background-color: var(--secondary);
|
31 |
+
color: var(--foreground);
|
32 |
+
border: 1px solid var(--primary);
|
33 |
+
}
|
34 |
+
|
35 |
+
.form-group input:focus {
|
36 |
+
border-color: var(--accent);
|
37 |
+
outline: none;
|
38 |
+
}
|
39 |
+
|
40 |
+
.submit-button {
|
41 |
+
width: 100%;
|
42 |
+
padding: 10px;
|
43 |
+
color: var(--foreground);
|
44 |
+
background-color: var(--primary);
|
45 |
+
border: none;
|
46 |
+
border-radius: 5px;
|
47 |
+
cursor: pointer;
|
48 |
+
}
|
49 |
+
|
50 |
+
.submit-button:hover {
|
51 |
+
background-color: var(--secondary);
|
52 |
+
}
|
53 |
+
|
54 |
+
.nexus-auth-signup-login {
|
55 |
+
text-align: center;
|
56 |
+
margin-top: 50px;
|
57 |
+
}
|
58 |
+
|
59 |
+
.nexus-auth-signup-login h1 {
|
60 |
+
margin-bottom: 20px;
|
61 |
+
color: var(--foreground);
|
62 |
+
}
|
63 |
+
|
64 |
+
.nexus-auth-signup-login button {
|
65 |
+
margin-top: 20px;
|
66 |
+
padding: 10px 20px;
|
67 |
+
color: var(--foreground);
|
68 |
+
background-color: var(--primary);
|
69 |
+
border: none;
|
70 |
+
border-radius: 5px;
|
71 |
+
cursor: pointer;
|
72 |
+
}
|
73 |
+
|
74 |
+
.nexus-auth-signup-login button:hover {
|
75 |
+
background-color: var(--secondary);
|
76 |
+
}
|
frontend/app/components/NexusAuth.js
ADDED
@@ -0,0 +1,90 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
'use client';
|
2 |
+
import './NexusAuth.css';
|
3 |
+
import { useState } from "react";
|
4 |
+
|
5 |
+
const SignupForm = ({ onSignup }) => {
|
6 |
+
const [username, setUsername] = useState('');
|
7 |
+
const [password, setPassword] = useState('');
|
8 |
+
const [email, setEmail] = useState('');
|
9 |
+
|
10 |
+
const handleSubmit = (e) => {
|
11 |
+
e.preventDefault();
|
12 |
+
onSignup({ username, password, email });
|
13 |
+
};
|
14 |
+
|
15 |
+
return (
|
16 |
+
<form onSubmit={handleSubmit} className="nexus-auth-form">
|
17 |
+
<h2>Signup</h2>
|
18 |
+
<div className="form-group">
|
19 |
+
<label>Username:</label>
|
20 |
+
<input type="text" value={username} onChange={(e) => setUsername(e.target.value)} required />
|
21 |
+
</div>
|
22 |
+
<div className="form-group">
|
23 |
+
<label>Password:</label>
|
24 |
+
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
|
25 |
+
</div>
|
26 |
+
<div className="form-group">
|
27 |
+
<label>Email (optional):</label>
|
28 |
+
<input type="email" value={email} onChange={(e) => setEmail(e.target.value)} />
|
29 |
+
</div>
|
30 |
+
<button type="submit" className="submit-button">Signup</button>
|
31 |
+
</form>
|
32 |
+
);
|
33 |
+
};
|
34 |
+
|
35 |
+
const LoginForm = ({ onLogin }) => {
|
36 |
+
const [username, setUsername] = useState('');
|
37 |
+
const [password, setPassword] = useState('');
|
38 |
+
|
39 |
+
const handleSubmit = (e) => {
|
40 |
+
e.preventDefault();
|
41 |
+
onLogin({ username, password });
|
42 |
+
};
|
43 |
+
|
44 |
+
return (
|
45 |
+
<form onSubmit={handleSubmit} className="nexus-auth-form">
|
46 |
+
<h2>Login</h2>
|
47 |
+
<div className="form-group">
|
48 |
+
<label>Username:</label>
|
49 |
+
<input type="text" value={username} onChange={(e) => setUsername(e.target.value)} required />
|
50 |
+
</div>
|
51 |
+
<div className="form-group">
|
52 |
+
<label>Password:</label>
|
53 |
+
<input type="password" value={password} onChange={(e) => setPassword(e.target.value)} required />
|
54 |
+
</div>
|
55 |
+
<button type="submit" className="submit-button">Login</button>
|
56 |
+
</form>
|
57 |
+
);
|
58 |
+
};
|
59 |
+
|
60 |
+
export const NexusAuthWrapper = ({ children }) =>{
|
61 |
+
const [isloggedin, setIsloggedin] = useState(false);
|
62 |
+
const [isSignup, setIsSignup] = useState(true);
|
63 |
+
|
64 |
+
const handleSignup = (data) => {
|
65 |
+
// Handle signup logic here
|
66 |
+
console.log('Signup data:', data);
|
67 |
+
setIsloggedin(true);
|
68 |
+
};
|
69 |
+
|
70 |
+
|
71 |
+
const handleLogin = (data) => {
|
72 |
+
// Handle login logic here
|
73 |
+
console.log('Login data:', data);
|
74 |
+
setIsloggedin(true);
|
75 |
+
};
|
76 |
+
|
77 |
+
return (
|
78 |
+
<div>
|
79 |
+
{isloggedin ? children :
|
80 |
+
<div className="nexus-auth-signup-login">
|
81 |
+
<h1>Nexus Accounts</h1>
|
82 |
+
{isSignup ? <SignupForm onSignup={handleSignup} /> : <LoginForm onLogin={handleLogin} />}
|
83 |
+
<button onClick={() => setIsSignup(!isSignup)}>
|
84 |
+
{isSignup ? 'Switch to Login' : 'Switch to Signup'}
|
85 |
+
</button>
|
86 |
+
</div>
|
87 |
+
}
|
88 |
+
</div>
|
89 |
+
);
|
90 |
+
};
|
frontend/app/globals.css
CHANGED
@@ -1,13 +1,9 @@
|
|
1 |
:root {
|
2 |
-
--background: #
|
3 |
-
--foreground: #
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
:root {
|
8 |
-
--background: #0a0a0a;
|
9 |
-
--foreground: #ededed;
|
10 |
-
}
|
11 |
}
|
12 |
|
13 |
html,
|
@@ -31,12 +27,32 @@ body {
|
|
31 |
}
|
32 |
|
33 |
a {
|
34 |
-
color:
|
35 |
text-decoration: none;
|
36 |
}
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
42 |
}
|
|
|
1 |
:root {
|
2 |
+
--background: #1e1e2f;
|
3 |
+
--foreground: #e0e0e0;
|
4 |
+
--primary: #3a3a5f;
|
5 |
+
--secondary: #2a2a4f;
|
6 |
+
--accent: #4a4a7f;
|
|
|
|
|
|
|
|
|
7 |
}
|
8 |
|
9 |
html,
|
|
|
27 |
}
|
28 |
|
29 |
a {
|
30 |
+
color: var(--accent);
|
31 |
text-decoration: none;
|
32 |
}
|
33 |
|
34 |
+
button {
|
35 |
+
background-color: var(--primary);
|
36 |
+
color: var(--foreground);
|
37 |
+
border: none;
|
38 |
+
padding: 10px 20px;
|
39 |
+
cursor: pointer;
|
40 |
+
font-size: 1rem;
|
41 |
+
}
|
42 |
+
|
43 |
+
button:hover {
|
44 |
+
background-color: var(--secondary);
|
45 |
+
}
|
46 |
+
|
47 |
+
input {
|
48 |
+
background-color: var(--secondary);
|
49 |
+
color: var(--foreground);
|
50 |
+
border: 1px solid var(--primary);
|
51 |
+
padding: 10px;
|
52 |
+
font-size: 1rem;
|
53 |
+
}
|
54 |
+
|
55 |
+
input:focus {
|
56 |
+
border-color: var(--accent);
|
57 |
+
outline: none;
|
58 |
}
|
frontend/app/layout.js
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import { Geist, Geist_Mono } from "next/font/google";
|
2 |
import "./globals.css";
|
|
|
3 |
|
4 |
const geistSans = Geist({
|
5 |
variable: "--font-geist-sans",
|
@@ -11,16 +12,13 @@ const geistMono = Geist_Mono({
|
|
11 |
subsets: ["latin"],
|
12 |
});
|
13 |
|
14 |
-
export const metadata = {
|
15 |
-
title: "Create Next App",
|
16 |
-
description: "Generated by create next app",
|
17 |
-
};
|
18 |
-
|
19 |
export default function RootLayout({ children }) {
|
20 |
return (
|
21 |
<html lang="en">
|
22 |
<body className={`${geistSans.variable} ${geistMono.variable}`}>
|
|
|
23 |
{children}
|
|
|
24 |
</body>
|
25 |
</html>
|
26 |
);
|
|
|
1 |
import { Geist, Geist_Mono } from "next/font/google";
|
2 |
import "./globals.css";
|
3 |
+
import { NexusAuthWrapper } from "./components/NexusAuth";
|
4 |
|
5 |
const geistSans = Geist({
|
6 |
variable: "--font-geist-sans",
|
|
|
12 |
subsets: ["latin"],
|
13 |
});
|
14 |
|
|
|
|
|
|
|
|
|
|
|
15 |
export default function RootLayout({ children }) {
|
16 |
return (
|
17 |
<html lang="en">
|
18 |
<body className={`${geistSans.variable} ${geistMono.variable}`}>
|
19 |
+
<NexusAuthWrapper>
|
20 |
{children}
|
21 |
+
</NexusAuthWrapper>
|
22 |
</body>
|
23 |
</html>
|
24 |
);
|
frontend/app/lib/Nexus_Auth_API.js
ADDED
@@ -0,0 +1,66 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import axios from 'axios';
|
2 |
+
|
3 |
+
const BASE_URL = 'http://localhost:YOUR_API_SERVER_PORT/v1/api/auth';
|
4 |
+
|
5 |
+
export const signup = async (username, password, email) => {
|
6 |
+
try {
|
7 |
+
const response = await axios.post(`${BASE_URL}/signup`, {
|
8 |
+
username,
|
9 |
+
password,
|
10 |
+
email,
|
11 |
+
});
|
12 |
+
return response.data;
|
13 |
+
} catch (error) {
|
14 |
+
throw new Error(error.response.data.detail);
|
15 |
+
}
|
16 |
+
};
|
17 |
+
|
18 |
+
export const login = async (username, password) => {
|
19 |
+
try {
|
20 |
+
const response = await axios.post(`${BASE_URL}/login`, {
|
21 |
+
username,
|
22 |
+
password,
|
23 |
+
});
|
24 |
+
return response.data;
|
25 |
+
} catch (error) {
|
26 |
+
throw new Error(error.response.data.detail);
|
27 |
+
}
|
28 |
+
};
|
29 |
+
|
30 |
+
export const logout = async (userId, token) => {
|
31 |
+
try {
|
32 |
+
await axios.post(`${BASE_URL}/logout`, {
|
33 |
+
user_id: userId,
|
34 |
+
token,
|
35 |
+
});
|
36 |
+
} catch (error) {
|
37 |
+
console.error(error); // Handle logout errors gracefully
|
38 |
+
}
|
39 |
+
};
|
40 |
+
|
41 |
+
export const validateToken = async (userId, token) => {
|
42 |
+
try {
|
43 |
+
const response = await axios.get(`${BASE_URL}/validate`, {
|
44 |
+
params: {
|
45 |
+
user_id: userId,
|
46 |
+
token,
|
47 |
+
},
|
48 |
+
});
|
49 |
+
return response.data;
|
50 |
+
} catch (error) {
|
51 |
+
throw new Error(error.response.data.detail);
|
52 |
+
}
|
53 |
+
};
|
54 |
+
|
55 |
+
export const updateUser = async (userId, token, updateData) => {
|
56 |
+
try {
|
57 |
+
const response = await axios.put(`${BASE_URL}/user/update`, updateData, {
|
58 |
+
headers: {
|
59 |
+
Authorization: `Bearer ${token}`,
|
60 |
+
},
|
61 |
+
});
|
62 |
+
return response.data;
|
63 |
+
} catch (error) {
|
64 |
+
throw new Error(error.response.data.detail);
|
65 |
+
}
|
66 |
+
};
|