diff --git a/.env b/.env new file mode 100644 index 0000000..58ea260 --- /dev/null +++ b/.env @@ -0,0 +1,2 @@ +USERNAME="Svr_admin" +PASSWORD="YP6t1kV6rmviuQG" \ No newline at end of file diff --git a/actions/login.actions.ts b/actions/login.actions.ts new file mode 100644 index 0000000..57d692f --- /dev/null +++ b/actions/login.actions.ts @@ -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 }); + } +} diff --git a/app/(root)/add-download/page.tsx b/app/(root)/add-download/page.tsx new file mode 100644 index 0000000..5bf4dc3 --- /dev/null +++ b/app/(root)/add-download/page.tsx @@ -0,0 +1,7 @@ +import React from 'react'; + +const AddDownload = () => { + return
Welcome to downloads
; +}; + +export default AddDownload; diff --git a/app/(root)/login/page.tsx b/app/(root)/login/page.tsx new file mode 100644 index 0000000..2d9d1aa --- /dev/null +++ b/app/(root)/login/page.tsx @@ -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) => { + 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 ( +
+
+ + ) => { + setUsername(e.target.value); + }} + /> +
+
+ + ) => { + setPassword(e.target.value); + }} + /> +
+ +
+ ); +}; + +export default Login; diff --git a/app/api/login/route.ts b/app/api/login/route.ts new file mode 100644 index 0000000..b731755 --- /dev/null +++ b/app/api/login/route.ts @@ -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 diff --git a/app/api/protected/route.ts b/app/api/protected/route.ts new file mode 100644 index 0000000..e69de29 diff --git a/package.json b/package.json index 40ae0d3..b383e5c 100644 --- a/package.json +++ b/package.json @@ -20,11 +20,13 @@ "@radix-ui/themes": "^3.0.5", "class-variance-authority": "^0.7.0", "clsx": "^2.1.1", + "dotenv": "^16.4.5", "framer-motion": "^11.2.10", "lucide-react": "^0.394.0", "mini-svg-data-uri": "^1.4.4", "next": "14.2.3", "next-themes": "^0.3.0", + "nookies": "^2.5.2", "react": "^18", "react-dom": "^18", "react-fontawesome": "^1.7.1", diff --git a/tsconfig.json b/tsconfig.json index e7ff90f..f834b79 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -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"] }