parent
4f97c1ea6a
commit
0f133ca467
@ -0,0 +1,69 @@
|
||||
import { FC, useContext } from 'react'
|
||||
|
||||
interface Props {
|
||||
}
|
||||
|
||||
const Dashboard:FC <Props> = () => {
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
<div className="stats shadow">
|
||||
|
||||
<div className="stat">
|
||||
<div className="stat-figure text-primary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" className="inline-block w-8 h-8 stroke-current"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"></path></svg>
|
||||
</div>
|
||||
<div className="stat-title">Total Likes</div>
|
||||
<div className="stat-value text-primary">25.6K</div>
|
||||
<div className="stat-desc">21% more than last month</div>
|
||||
</div>
|
||||
|
||||
<div className="stat">
|
||||
<div className="stat-figure text-secondary">
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" className="inline-block w-8 h-8 stroke-current"><path strokeLinecap="round" strokeLinejoin="round" strokeWidth="2" d="M13 10V3L4 14h7v7l9-11h-7z"></path></svg>
|
||||
</div>
|
||||
<div className="stat-title">Page Views</div>
|
||||
<div className="stat-value text-secondary">2.6M</div>
|
||||
<div className="stat-desc">21% more than last month</div>
|
||||
</div>
|
||||
|
||||
<div className="stat">
|
||||
<div className="stat-figure text-secondary">
|
||||
<div className="avatar online">
|
||||
<div className="w-16 rounded-full">
|
||||
<img src="/images/stock/photo-1534528741775-53994a69daeb.jpg" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div className="stat-value">86%</div>
|
||||
<div className="stat-title">Tasks done</div>
|
||||
<div className="stat-desc text-secondary">31 tasks remaining</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div className="carousel w-full">
|
||||
<div id="item1" className="carousel-item w-full">
|
||||
<img src="https://daisyui.com/images/stock/photo-1625726411847-8cbb60cc71e6.jpg" className="w-full" />
|
||||
</div>
|
||||
<div id="item2" className="carousel-item w-full">
|
||||
<img src="/images/stock/photo-1609621838510-5ad474b7d25d.jpg" className="w-full" />
|
||||
</div>
|
||||
<div id="item3" className="carousel-item w-full">
|
||||
<img src="/images/stock/photo-1414694762283-acccc27bca85.jpg" className="w-full" />
|
||||
</div>
|
||||
<div id="item4" className="carousel-item w-full">
|
||||
<img src="/images/stock/photo-1665553365602-b2fb8e5d1707.jpg" className="w-full" />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-center w-full py-2 gap-2">
|
||||
<a href="#item1" className="btn btn-xs">1</a>
|
||||
<a href="#item2" className="btn btn-xs">2</a>
|
||||
<a href="#item3" className="btn btn-xs">3</a>
|
||||
<a href="#item4" className="btn btn-xs">4</a>
|
||||
</div>
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default Dashboard;
|
@ -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 <Props> = () => {
|
||||
|
||||
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 (
|
||||
<>
|
||||
<form onSubmit={handleSubmit(onSubmit)}>
|
||||
<div className="form-control">
|
||||
<label className="label">
|
||||
<span className="label-text">Email</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Usuario"
|
||||
className="input input-bordered"
|
||||
{...register("user")}/>
|
||||
</div>
|
||||
<div className="form-control">
|
||||
<label className="label">
|
||||
<span className="label-text">Password</span>
|
||||
</label>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="password"
|
||||
className="input input-bordered"
|
||||
{...register("password")}
|
||||
/>
|
||||
<label className="label">
|
||||
<a href="#" className="label-text-alt link link-hover">Forgot password?</a>
|
||||
</label>
|
||||
</div>
|
||||
<div className="form-control mt-6">
|
||||
<button type="submit" className="btn btn-primary">Login</button>
|
||||
</div>
|
||||
</form>
|
||||
</>
|
||||
)
|
||||
}
|
@ -0,0 +1,29 @@
|
||||
import { Form } from "./form";
|
||||
|
||||
|
||||
const login = () => {
|
||||
|
||||
|
||||
return (
|
||||
<>
|
||||
|
||||
<div className="hero min-h-screen bg-base-200">
|
||||
<div className="hero-content flex-col lg:flex-row-reverse">
|
||||
<div className="text-center lg:text-left">
|
||||
<h1 className="text-5xl font-bold">Login now!</h1>
|
||||
<p className="py-6">Provident cupiditate voluptatem et in. Quaerat fugiat ut assumenda excepturi exercitationem quasi. In deleniti eaque aut repudiandae et a id nisi.</p>
|
||||
</div>
|
||||
<div className="card flex-shrink-0 w-full max-w-sm shadow-2xl bg-base-100">
|
||||
<div className="card-body">
|
||||
<Form/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export default login;
|
@ -0,0 +1,12 @@
|
||||
import { FC } from 'react'
|
||||
|
||||
interface Props {
|
||||
}
|
||||
|
||||
export const Input:FC <Props> = () => {
|
||||
return (
|
||||
<>
|
||||
<input/>
|
||||
</>
|
||||
)
|
||||
}
|
@ -0,0 +1,3 @@
|
||||
export default function Button() {
|
||||
return <button>Click me</button>
|
||||
}
|
@ -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
|
||||
}
|
||||
|
||||
}
|
@ -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).*)',],
|
||||
}
|
@ -1,4 +1,8 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {}
|
||||
const nextConfig = {
|
||||
env: {
|
||||
API_URL: 'http://localhost:8081',
|
||||
},
|
||||
}
|
||||
|
||||
module.exports = nextConfig
|
||||
|
After Width: | Height: | Size: 80 KiB |
Loading…
Reference in new issue