diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx new file mode 100644 index 0000000..2ab9428 --- /dev/null +++ b/app/dashboard/page.tsx @@ -0,0 +1,69 @@ +import { FC, useContext } from 'react' + +interface Props { +} + + const Dashboard:FC = () => { + + + return ( + <> +
+ +
+
+ +
+
Total Likes
+
25.6K
+
21% more than last month
+
+ +
+
+ +
+
Page Views
+
2.6M
+
21% more than last month
+
+ +
+
+
+
+ +
+
+
+
86%
+
Tasks done
+
31 tasks remaining
+
+ +
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+
+ 1 + 2 + 3 + 4 +
+ + ) +} + +export default Dashboard; \ No newline at end of file diff --git a/app/layout.tsx b/app/layout.tsx index 71b3fbf..867736b 100644 --- a/app/layout.tsx +++ b/app/layout.tsx @@ -15,7 +15,9 @@ export default function RootLayout({ }) { return ( - {children} + + {children} + ) } diff --git a/app/login/form.tsx b/app/login/form.tsx new file mode 100644 index 0000000..b3724b9 --- /dev/null +++ b/app/login/form.tsx @@ -0,0 +1,72 @@ +'use client' + +import { FC } from 'react' +import { useBasicAuth } from 'hooks/useBasicAuth'; +import { useRouter } from 'next/navigation' +import { useForm } from 'react-hook-form'; +import Cookies from 'js-cookie'; + + +interface Props { +} + +export const Form:FC = () => { + + const router = useRouter(); + + const { register, handleSubmit, getValues, formState: { errors } } = useForm(); + + const onSubmit = async (entity: any) => { + console.log("on submit") + try { + + + const { data, error } = await useBasicAuth("/login",getValues("user"),getValues("password") ); + + if (error) { + console.log(error); + } else { + if (data && data.length>0){ + Cookies.set("token",data); + router.push("/dashboard"); + } + } + } catch (e) { + console.log("Post error:"); + console.table(e); + } + } + return ( + <> +
+
+ + +
+
+ + + +
+
+ +
+
+ + ) +} \ No newline at end of file diff --git a/app/login/page.tsx b/app/login/page.tsx new file mode 100644 index 0000000..fcae493 --- /dev/null +++ b/app/login/page.tsx @@ -0,0 +1,29 @@ +import { Form } from "./form"; + + +const login = () => { + + + return ( + <> + +
+
+
+

Login now!

+

Provident cupiditate voluptatem et in. Quaerat fugiat ut assumenda excepturi exercitationem quasi. In deleniti eaque aut repudiandae et a id nisi.

+
+
+
+
+
+
+
+
+ + + + ) +} + +export default login; diff --git a/app/page.tsx b/app/page.tsx index 745df65..a39a6a9 100644 --- a/app/page.tsx +++ b/app/page.tsx @@ -1,113 +1,19 @@ import Image from 'next/image' export default function Home() { + return (
-
-

- Get started by editing  - app/page.tsx -

-
- - By{' '} - Vercel Logo - +
) } diff --git a/components/Input.tsx b/components/Input.tsx new file mode 100644 index 0000000..23cc5e0 --- /dev/null +++ b/components/Input.tsx @@ -0,0 +1,12 @@ +import { FC } from 'react' + +interface Props { +} + +export const Input:FC = () => { + return ( + <> + + + ) +} \ No newline at end of file diff --git a/components/button.tsx b/components/button.tsx new file mode 100644 index 0000000..d52c637 --- /dev/null +++ b/components/button.tsx @@ -0,0 +1,3 @@ +export default function Button() { + return + } \ No newline at end of file diff --git a/hooks/useBasicAuth.tsx b/hooks/useBasicAuth.tsx new file mode 100644 index 0000000..cd457b5 --- /dev/null +++ b/hooks/useBasicAuth.tsx @@ -0,0 +1,40 @@ +import {Buffer} from 'buffer'; + +const fecher = async (url: string, token: string) => { + return await fetch(url, { + method: 'POST', + + headers: { + 'Authorization' :token + }, + }); + } + + export const useBasicAuth = async (endpoint: string, username:string, password: string) => { + //url= process.env.API_URL+url; + const token = 'Basic '+ Buffer.from(username + ':' + password).toString('base64'); + let data; + let error; + try{ + const url = process.env.API_URL + endpoint; + + const response = await fecher(url, token) + + if (response.ok){ + const token = response.headers.get('Authorization') ; + if (token){ + data = token.replaceAll("Basic ","") + } + }else { + const trace = await response.json(); + error = "Servidor: "+ trace.message; + } + }catch (trace){ + error = "Cliente: "+trace; + } + return { + data, + error + } + + } \ No newline at end of file diff --git a/middleware.ts b/middleware.ts new file mode 100644 index 0000000..5d9698a --- /dev/null +++ b/middleware.ts @@ -0,0 +1,18 @@ + +import { NextResponse } from 'next/server' +import type { NextRequest } from 'next/server' + + +export function middleware(request: NextRequest) { + + const token = request.cookies.get('token')?.value + console.log("token"+token) + if (!token) { + return NextResponse.rewrite(new URL('/login', request.url)) + } + +} + +export const config = { + matcher: ['/((?!api|_next/static|_next/image|favicon.ico|login).*)',], +} diff --git a/next.config.js b/next.config.js index 767719f..3f66cfa 100644 --- a/next.config.js +++ b/next.config.js @@ -1,4 +1,8 @@ /** @type {import('next').NextConfig} */ -const nextConfig = {} +const nextConfig = { + env: { + API_URL: 'http://localhost:8081', + }, +} module.exports = nextConfig diff --git a/package-lock.json b/package-lock.json index c73f8ba..c159a4b 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,12 +12,18 @@ "@types/react": "18.0.31", "@types/react-dom": "18.2.4", "autoprefixer": "10.4.14", + "js-cookie": "^3.0.5", "next": "13.4.4", "postcss": "8.4.21", "react": "18.2.0", "react-dom": "18.2.0", + "react-hook-form": "^7.45.0", "tailwindcss": "3.3.0", - "typescript": "5.0.2" + "typescript": "^5.1.3" + }, + "devDependencies": { + "@types/js-cookie": "^3.0.3", + "daisyui": "^3.1.5" } }, "node_modules/@next/env": { @@ -200,6 +206,12 @@ "tslib": "^2.4.0" } }, + "node_modules/@types/js-cookie": { + "version": "3.0.3", + "resolved": "https://registry.npmjs.org/@types/js-cookie/-/js-cookie-3.0.3.tgz", + "integrity": "sha512-Xe7IImK09HP1sv2M/aI+48a20VX+TdRJucfq4vfRVy6nWN8PYPOEnlMRSgxJAgYQIXJVL8dZ4/ilAM7dWNaOww==", + "dev": true + }, "node_modules/@types/node": { "version": "18.15.11", "resolved": "https://registry.npmjs.org/@types/node/-/node-18.15.11.tgz", @@ -432,6 +444,12 @@ "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz", "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==" }, + "node_modules/colord": { + "version": "2.9.3", + "resolved": "https://registry.npmjs.org/colord/-/colord-2.9.3.tgz", + "integrity": "sha512-jeC1axXpnb0/2nn/Y1LPuLdgXBLH7aDcHu4KEKfqw3CUhX7ZpfBSlPKyqXE6btIgEzfWtrX3/tyBCaCvXvMkOw==", + "dev": true + }, "node_modules/commander": { "version": "4.1.1", "resolved": "https://registry.npmjs.org/commander/-/commander-4.1.1.tgz", @@ -445,6 +463,16 @@ "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", "integrity": "sha512-/Srv4dswyQNBfohGpz9o6Yb3Gz3SrUDqBH5rTuhGR7ahtlbYKnVxw2bCFMRljaA7EXHaXZ8wsHdodFvbkhKmqg==" }, + "node_modules/css-selector-tokenizer": { + "version": "0.8.0", + "resolved": "https://registry.npmjs.org/css-selector-tokenizer/-/css-selector-tokenizer-0.8.0.tgz", + "integrity": "sha512-Jd6Ig3/pe62/qe5SBPTN8h8LeUg/pT4lLgtavPf7updwwHpvFzxvOQBHYj2LZDMjUnBzgvIUSjRcf6oT5HzHFg==", + "dev": true, + "dependencies": { + "cssesc": "^3.0.0", + "fastparse": "^1.1.2" + } + }, "node_modules/cssesc": { "version": "3.0.0", "resolved": "https://registry.npmjs.org/cssesc/-/cssesc-3.0.0.tgz", @@ -461,6 +489,28 @@ "resolved": "https://registry.npmjs.org/csstype/-/csstype-3.1.1.tgz", "integrity": "sha512-DJR/VvkAvSZW9bTouZue2sSxDwdTN92uHjqeKVm+0dAqdfNykRzQ95tay8aXMBAAPpUiq4Qcug2L7neoRh2Egw==" }, + "node_modules/daisyui": { + "version": "3.1.5", + "resolved": "https://registry.npmjs.org/daisyui/-/daisyui-3.1.5.tgz", + "integrity": "sha512-3nk5L//IU31ISzsonKEFG8ris8hS/MRAc+PrOTOyRbssjv1fYmNKSdIrOhG6op2ED3RyJL4p6I81JUwd7RWqTw==", + "dev": true, + "dependencies": { + "colord": "^2.9", + "css-selector-tokenizer": "^0.8", + "postcss-js": "^4", + "tailwindcss": "^3" + }, + "engines": { + "node": ">=16.9.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/daisyui" + }, + "peerDependencies": { + "postcss": "^8" + } + }, "node_modules/didyoumean": { "version": "1.2.2", "resolved": "https://registry.npmjs.org/didyoumean/-/didyoumean-1.2.2.tgz", @@ -510,6 +560,12 @@ "node": ">= 6" } }, + "node_modules/fastparse": { + "version": "1.1.2", + "resolved": "https://registry.npmjs.org/fastparse/-/fastparse-1.1.2.tgz", + "integrity": "sha512-483XLLxTVIwWK3QTrMGRqUfUpoOs/0hbQrl2oz4J0pAcm3A3bu84wxTFqGqkJzewCLdME38xJLJAxBABfQT8sQ==", + "dev": true + }, "node_modules/fastq": { "version": "1.15.0", "resolved": "https://registry.npmjs.org/fastq/-/fastq-1.15.0.tgz", @@ -676,6 +732,14 @@ "jiti": "bin/jiti.js" } }, + "node_modules/js-cookie": { + "version": "3.0.5", + "resolved": "https://registry.npmjs.org/js-cookie/-/js-cookie-3.0.5.tgz", + "integrity": "sha512-cEiJEAEoIbWfCZYKWhVwFuvPX1gETRYPw6LlaTKoxD3s2AkXzkCjnp6h0V77ozyqj0jakteJ4YqDJT830+lVGw==", + "engines": { + "node": ">=14" + } + }, "node_modules/js-tokens": { "version": "4.0.0", "resolved": "https://registry.npmjs.org/js-tokens/-/js-tokens-4.0.0.tgz", @@ -1098,6 +1162,21 @@ "react": "^18.2.0" } }, + "node_modules/react-hook-form": { + "version": "7.45.0", + "resolved": "https://registry.npmjs.org/react-hook-form/-/react-hook-form-7.45.0.tgz", + "integrity": "sha512-AbHeZ4ad+0dEIknSW9dBgIwcvRDfZ1O97sgj75WaMdOX0eg8TBiUf9wxzVkIjZbk76BBIE9lmFOzyD4PN80ZQg==", + "engines": { + "node": ">=12.22.0" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/react-hook-form" + }, + "peerDependencies": { + "react": "^16.8.0 || ^17 || ^18" + } + }, "node_modules/read-cache": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/read-cache/-/read-cache-1.0.0.tgz", @@ -1323,15 +1402,15 @@ "integrity": "sha512-336iVw3rtn2BUK7ORdIAHTyxHGRIHVReokCR3XjbckJMK7ms8FysBfhLR8IXnAgy7T0PTPNBWKiH514FOW/WSg==" }, "node_modules/typescript": { - "version": "5.0.2", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.0.2.tgz", - "integrity": "sha512-wVORMBGO/FAs/++blGNeAVdbNKtIh1rbBL2EyQ1+J9lClJ93KiiKe8PmFIVdXhHcyv44SL9oglmfeSsndo0jRw==", + "version": "5.1.3", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.1.3.tgz", + "integrity": "sha512-XH627E9vkeqhlZFQuL+UsyAXEnibT0kWR2FWONlr4sTjvxyJYnyefgrkyECLzM5NenmKzRAy2rR/OlYLA1HkZw==", "bin": { "tsc": "bin/tsc", "tsserver": "bin/tsserver" }, "engines": { - "node": ">=12.20" + "node": ">=14.17" } }, "node_modules/update-browserslist-db": { diff --git a/package.json b/package.json index 58fcfe3..f4d6219 100644 --- a/package.json +++ b/package.json @@ -13,11 +13,17 @@ "@types/react": "18.0.31", "@types/react-dom": "18.2.4", "autoprefixer": "10.4.14", + "js-cookie": "^3.0.5", "next": "13.4.4", "postcss": "8.4.21", "react": "18.2.0", "react-dom": "18.2.0", + "react-hook-form": "^7.45.0", "tailwindcss": "3.3.0", - "typescript": "5.0.2" + "typescript": "^5.1.3" + }, + "devDependencies": { + "@types/js-cookie": "^3.0.3", + "daisyui": "^3.1.5" } } diff --git a/public/logo.png b/public/logo.png new file mode 100644 index 0000000..0ffc72e Binary files /dev/null and b/public/logo.png differ diff --git a/tailwind.config.js b/tailwind.config.js index 8c4d1b2..5716eea 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -14,5 +14,6 @@ module.exports = { }, }, }, - plugins: [], + plugins: [require("daisyui")], + } diff --git a/tsconfig.json b/tsconfig.json index edf14cc..8ddd855 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -19,8 +19,9 @@ "name": "next" } ], + "baseUrl": ".", "paths": { - "@/components/*": ["./*"] + "@/components/*": ["components/*"] } }, "include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],