Skip to content

Commit

Permalink
fix: post login authorization bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Kruceo committed Jun 28, 2024
1 parent 64886bc commit 0a1bdc9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 45 deletions.
2 changes: 1 addition & 1 deletion frontend/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@
"protocol": "http",
"port": "8888"
},
"dashboard_custom_page": null
"dashboard_custom_page": "https://www.gov.br/agricultura/pt-br/"
}
52 changes: 25 additions & 27 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,42 +28,40 @@ import icon from './assets/icon.svg'


function App() {
useEffect(()=>{
useEffect(() => {
document.head.innerHTML += `<link rel="icon" type="image/svg+xml" href="${icon}" />`
},[])
}, [])
return (
<>
<PopupContext>
<ErrorHandler>
<TableEngine>

<Routes>
<Route path='/' element={<Proteged>{<ViewDashboard />}</Proteged>} />
<Route path='/view/bote' element={<Proteged>{<ViewBotes />}</Proteged>} />
<Route path='/view/produto' element={<Proteged>{<ViewProducts />}</Proteged>} />
<Route path='/view/fornecedor' element={<Proteged>{<ViewVendors />}</Proteged>} />
<Route path='/create/entrada' element={<Proteged>{<CreateEntry type={0} />}</Proteged>} />
<Route path='/create/saida' element={<Proteged>{<CreateEntry type={1} />}</Proteged>} />
<Route path='/view/transacao/' element={<Proteged>{<ViewEntry />}</Proteged>} />
<Route path='/edit/transacao/' element={<Proteged>{<EditEntry />}</Proteged>} />
<Route path='/details/transacao/' element={<Proteged>{<DetailsEntry />}</Proteged>} />
<Route path='/print/transacao/' element={<Proteged>{<PrintEntry />}</Proteged>} />
<Route path='/report/1' element={<Proteged>{<ViewReports />}</Proteged>} />
<Route path='/report/2' element={<Proteged>{<ViewBoatEntryComparationReport />}</Proteged>} />
<Route path='/report/3' element={<Proteged>{<ViewTransComparationReport />}</Proteged>} />
<Route path='/report/4' element={<Proteged>{<ViewEntryItemReport />}</Proteged>} />
<Route path='/report/5' element={<Proteged>{<ViewTotalsByVendors />}</Proteged>} />
<Routes>
<Route path='/' element={<Proteged key={"page" + 0}>{<ViewDashboard />}</Proteged>} />
<Route path='/view/bote' element={<Proteged key={"page" + 1}>{<ViewBotes />}</Proteged>} />
<Route path='/view/produto' element={<Proteged key={"page" + 2}>{<ViewProducts />}</Proteged>} />
<Route path='/view/fornecedor' element={<Proteged key={"page" + 3}>{<ViewVendors />}</Proteged>} />
<Route path='/create/entrada' element={<Proteged key={"page" + 4}>{<CreateEntry type={0} />}</Proteged>} />
<Route path='/create/saida' element={<Proteged key={"page" + 5}>{<CreateEntry type={1} />}</Proteged>} />
<Route path='/view/transacao/' element={<Proteged key={"page" + 6}>{<ViewEntry />}</Proteged>} />
<Route path='/edit/transacao/' element={<Proteged key={"page" + 7}>{<EditEntry />}</Proteged>} />
<Route path='/details/transacao/' element={<Proteged key={"page" + 8}>{<DetailsEntry />}</Proteged>} />
<Route path='/print/transacao/' element={<Proteged key={"page" + 9}>{<PrintEntry />}</Proteged>} />
<Route path='/report/1' element={<Proteged key={"page" + 10}>{<ViewReports />}</Proteged>} />
<Route path='/report/2' element={<Proteged key={"page" + 11}>{<ViewBoatEntryComparationReport />}</Proteged>} />
<Route path='/report/3' element={<Proteged key={"page" + 12}>{<ViewTransComparationReport />}</Proteged>} />
<Route path='/report/4' element={<Proteged key={"page" + 13}>{<ViewEntryItemReport />}</Proteged>} />
<Route path='/report/5' element={<Proteged key={"page" + 14}>{<ViewTotalsByVendors />}</Proteged>} />
<Route path='/login' element={<LoginScreen />} />
<Route path='/receipt/once' element={<ViewReceipt />} />
<Route path='/receipt/transaction' element={<ViewPerTransReceipt />} />
<Route path='/receipt/vendor' element={<ViewPerVendorReceipt />} />

<Route path='/login' element={<LoginScreen />} />
<Route path='/teste' element={<Proteged key={"page-testes"}><Teste /></Proteged>} />

<Route path='/receipt/once' element={<ViewReceipt />} />
<Route path='/receipt/transaction' element={<ViewPerTransReceipt />} />
<Route path='/receipt/vendor' element={<ViewPerVendorReceipt />} />

<Route path='/teste' element={<Teste />} />

<Route path='/*' element={<View404 />} />
</Routes>
<Route path='/*' element={<View404 />} />
</Routes>
</TableEngine>
</ErrorHandler>
</PopupContext>
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/components/Layout/Bar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@ export default function Bar() {
else setIsOpenDropDown(false)
}

useEffect(() => window.addEventListener('click', clickHandler), [isMouseOverIcon, isMouseOverPanel])
useEffect(() => {
window.addEventListener('click', clickHandler)
return () => removeEventListener("click", clickHandler)
}, [isMouseOverIcon, isMouseOverPanel])

const user = Cookies.get("user")
return <>
Expand All @@ -38,8 +41,8 @@ export default function Bar() {
isOpenDropDown ? <div
onMouseLeave={() => setIsMouseOverPanel(false)}
onMouseEnter={() => setIsMouseOverPanel(true)}
className="px-4 top-full left-full -translate-x-full absolute">
<div className="bg-subpanel border-borders border shadow-xl">
className="px-4 top-full left-full -translate-x-full absolute">
<div className="bg-subpanel border-borders border rounded-panel-default shadow-xl">
<div className="flex flex-col justify-center items-center p-4 min-w-40">
<UserIcon className="mb-2" />
<p className="capitalize font-bold text-current">{user}</p>
Expand Down
14 changes: 7 additions & 7 deletions frontend/src/components/Layout/ProtegedRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
import { PropsWithChildren, useEffect, useState } from "react";
import { Key, ReactNode, useEffect, useState } from "react";
import { api_address, api_port, api_protocol } from "../../constants/backend/backend";
import axios from "axios";
import { useNavigate } from "react-router-dom";
import Bar from "./Bar";
import Cookies from 'js-cookie'

export function Proteged(props: PropsWithChildren) {
export function Proteged(props: {key:Key,children?:ReactNode}) {

const navigate = useNavigate()
const [authorized, setAuthorized] = useState<undefined | boolean>()

useEffect(() => {
(async () => {
try {
const response = await axios.get(api_protocol + "://" + api_address + ":" + api_port + "/auth/validate",
{
withCredentials: true,
headers:{Authorization:`bearer ${window.localStorage.getItem("auth-token")}`}
})
const response = await axios.get(api_protocol + "://" + api_address + ":" + api_port + "/auth/validate",
{
withCredentials: true,
headers: { Authorization: `bearer ${window.localStorage.getItem("auth-token")}` }
})
if (response.data && !response.data.error) {
Cookies.set("user", response.data.user, { domain: api_address })
setAuthorized(true)
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/pages/Teste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ function TestPrinterSect() {
return <>
<h3>Testar Impressora</h3>
<p>Width: {pWidth} chars</p>
<FormInput></FormInput>
<FormInput onChange={(e)=>setPInput(e.currentTarget.value)}/>
<Button onClick={() => {
thermalPrinter.print([["println", pInput], ['cut']]).catch(err => {
setErr(err.message)
Expand Down
1 change: 0 additions & 1 deletion frontend/src/components/pages/Transactions/CreateEntry.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,6 @@ export default function CreateEntry(props: { type: 0 | 1 }) {
<Bar />
<SideBar />
<Content>
{finalizing ? "true" : "false"}
<SkeletonContainer className={`${finalizing ? "" : "w-0 h-0 invisible"} z-20 w-full h-full left-0 top-0 fixed`} />
<HelpButton content={"F8 - Finalizar e adicionar nova entrada\nF9 - Finalizar e adicionar nova saída"} className="absolute left-full -translate-x-full z-50" />
<section className="py-8 px-4 border-b border-borders relative flex w-full">
Expand Down
5 changes: 0 additions & 5 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,6 @@ i {
font-family: icomoon, "Outfit", Inter, system-ui, Avenir,Arial, Helvetica, sans-serif;
}

/* option{ */
/* background-color:#171717; */
/* color: #c0c0c0; */
/* } */

:root {
font-family: Rubik, Inter, system-ui, Avenir,Arial, Helvetica, sans-serif;
/* letter-spacing: -1px; */
Expand Down

0 comments on commit 0a1bdc9

Please sign in to comment.