Co-authored-by: Abhijit Bhattacharjee <Proxyy587@users.noreply.github.com>

This commit is contained in:
NerfedJabolo 2024-06-19 21:42:51 +03:00
parent 7c2d8ceba3
commit eee76eaa66
8 changed files with 108 additions and 1 deletions

2
.env Normal file
View file

@ -0,0 +1,2 @@
USERNAME="Svr_admin"
PASSWORD="YP6t1kV6rmviuQG"

13
actions/login.actions.ts Normal file
View file

@ -0,0 +1,13 @@
'use server';
import { NextApiRequest } from 'next';
import { NextResponse } from 'next/server';
export async function POST(req: NextApiRequest) {
const { username, password } = await req.body;
if (username === process.env.USERNAME && password === process.env.PASSWORD) {
return NextResponse.json({ success: true });
} else {
return NextResponse.json({ success: false });
}
}

View file

@ -0,0 +1,7 @@
import React from 'react';
const AddDownload = () => {
return <div>Welcome to downloads</div>;
};
export default AddDownload;

52
app/(root)/login/page.tsx Normal file
View file

@ -0,0 +1,52 @@
'use client';
import React, { useState } from 'react';
import { useRouter } from 'next/navigation';
const Login = () => {
const [username, setUsername] = useState('');
const [password, setPassword] = useState('');
const router = useRouter();
const handleSubmit = async (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
const res = await fetch('/api/login', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ username, password }),
});
if (res.ok) {
router.push('/add-download');
} else {
alert(res.status);
}
};
return (
<form onSubmit={handleSubmit}>
<div>
<label>Username:</label>
<input
type="text"
value={username}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setUsername(e.target.value);
}}
/>
</div>
<div>
<label>Password:</label>
<input
type="text"
value={password}
onChange={(e: React.ChangeEvent<HTMLInputElement>) => {
setPassword(e.target.value);
}}
/>
</div>
<button type="submit">Login</button>
</form>
);
};
export default Login;

31
app/api/login/route.ts Normal file
View file

@ -0,0 +1,31 @@
// import { NextResponse } from 'next/server';
// import { setCookie } from 'nookies';
// require('dotenv').config();
// // nvm, clerk is overkill for one u
// export async function POST(request: NextApiRequest) {
// const { username, password } = await request.json();
// console.log(username, password);
// console.log(process.env.PASSWORD);
// if (username === process.env.USERNAME && password === process.env.PASSWORD) {
// const response = NextResponse.json(
// { message: 'Login successful' },
// { status: 200 }
// );
// setCookie({ res: response }, 'token', 'your-auth-token', {
// httpOnly: true,
// secure: process.env.NODE_ENV !== 'development',
// maxAge: 30 * 24 * 60 * 60,
// path: '/',
// });
// return response;
// } else {
// return NextResponse.json({ message: 'Login failed' }, { status: 401 });
// }
// }
// im gonna create server actions

View file

View file

@ -20,11 +20,13 @@
"@radix-ui/themes": "^3.0.5", "@radix-ui/themes": "^3.0.5",
"class-variance-authority": "^0.7.0", "class-variance-authority": "^0.7.0",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"dotenv": "^16.4.5",
"framer-motion": "^11.2.10", "framer-motion": "^11.2.10",
"lucide-react": "^0.394.0", "lucide-react": "^0.394.0",
"mini-svg-data-uri": "^1.4.4", "mini-svg-data-uri": "^1.4.4",
"next": "14.2.3", "next": "14.2.3",
"next-themes": "^0.3.0", "next-themes": "^0.3.0",
"nookies": "^2.5.2",
"react": "^18", "react": "^18",
"react-dom": "^18", "react-dom": "^18",
"react-fontawesome": "^1.7.1", "react-fontawesome": "^1.7.1",

View file

@ -21,6 +21,6 @@
"@/*": ["./*"] "@/*": ["./*"]
} }
}, },
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts", "lib/Hoc/withAuth.jsx"],
"exclude": ["node_modules"] "exclude": ["node_modules"]
} }