Skip to content

Commit 187ace1

Browse files
committed
refactor auth
1 parent 3e61bab commit 187ace1

18 files changed

+44
-15
lines changed

Diff for: .DS_Store

0 Bytes
Binary file not shown.

Diff for: frontend/package-lock.json

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: frontend/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"@auth0/auth0-react": "^2.2.4",
1414
"@react-google-maps/api": "^2.19.2",
15+
"@types/auth0": "^3.3.10",
1516
"axios": "^1.6.5",
1617
"emailjs-com": "^3.2.0",
1718
"react": "^18.2.0",

Diff for: frontend/src/App.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ const App: React.FC = () => {
1919
<BrowserRouter>
2020
<Auth0ProviderWithHistory>
2121
<div className="flex flex-col h-screen">
22-
<Header /> {/* This will always be displayed */}
22+
<Header />
2323
<main className="flex-grow">
2424
<Routes>
2525
<Route
@@ -50,7 +50,7 @@ const App: React.FC = () => {
5050
<Route path="/worker/:workerId" element={<WorkerDetailsPage />} />
5151
<Route path="/contact" element={<ContactForm />} />
5252
<Route path="/query-results" element={<QueryResultsPage />} />
53-
<Route path = "/login" element={<LoginPage />} />
53+
<Route path="/login" element={<LoginPage />} />
5454
</Routes>
5555
</main>
5656
<Footer />

Diff for: frontend/src/assets/OldCarpentry.png

-426 KB
Binary file not shown.

Diff for: frontend/src/assets/OldElectrical.png

-308 KB
Binary file not shown.

Diff for: frontend/src/assets/OldInsurance.png

-682 KB
Binary file not shown.

Diff for: frontend/src/assets/OldLawn.png

-557 KB
Binary file not shown.

Diff for: frontend/src/assets/OldLogo.png

-507 KB
Binary file not shown.

Diff for: frontend/src/assets/OldOne.png

-1.04 MB
Binary file not shown.

Diff for: frontend/src/assets/OldPainting.png

-506 KB
Binary file not shown.

Diff for: frontend/src/assets/OldPlumbing.png

-262 KB
Binary file not shown.

Diff for: frontend/src/assets/OldThree.png

-350 KB
Binary file not shown.

Diff for: frontend/src/assets/OldTwo.png

-773 KB
Binary file not shown.

Diff for: frontend/src/auth/auth0-provider-with-history.tsx

+17-6
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,27 @@
1-
import React from "react";
1+
import React, { ReactNode } from "react";
22
import { useNavigate } from "react-router-dom";
3-
import { Auth0Provider } from "@auth0/auth0-react";
3+
import { Auth0Provider, AppState } from "@auth0/auth0-react";
44

5-
const Auth0ProviderWithHistory: React.FC = ({ children }) => {
5+
interface Auth0ProviderWithHistoryProps {
6+
children: ReactNode;
7+
}
8+
9+
const Auth0ProviderWithHistory: React.FC<Auth0ProviderWithHistoryProps> = ({
10+
children,
11+
}) => {
612
const navigate = useNavigate();
713

8-
const onRedirectCallback = (appState: any) => {
14+
const onRedirectCallback = (appState?: AppState) => {
915
navigate(appState?.returnTo || "/home");
1016
};
1117

12-
const domain = import.meta.env.VITE_AUTH0_DOMAIN;
13-
const clientId = import.meta.env.VITE_AUTH0_CLIENT_ID;
18+
const domain = import.meta.env.VITE_AUTH0_DOMAIN as string;
19+
const clientId = import.meta.env.VITE_AUTH0_CLIENT_ID as string;
20+
21+
if (!domain || !clientId) {
22+
console.error("Auth0 environment variables are not set");
23+
return null;
24+
}
1425

1526
return (
1627
<Auth0Provider

Diff for: frontend/src/pages/ProctedPage.tsx

+13-5
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,27 @@
1-
import React from "react";
1+
import React, { ReactNode } from "react";
22
import { useAuth0 } from "@auth0/auth0-react";
33
import { Navigate } from "react-router-dom";
44

5-
const ProtectedRoute = ({ children }) => {
5+
interface ProtectedRouteProps {
6+
children: ReactNode;
7+
}
8+
9+
const ProtectedRoute: React.FC<ProtectedRouteProps> = ({ children }) => {
610
const { isAuthenticated, isLoading } = useAuth0();
711

812
if (isLoading) {
9-
return <div>Loading...</div>; // or any loading indicator you prefer
13+
return (
14+
<div className="flex justify-center items-center h-screen">
15+
<div className="animate-spin rounded-full h-32 w-32 border-b-2 border-gray-900"></div>
16+
</div>
17+
);
1018
}
1119

1220
if (!isAuthenticated) {
13-
return <Navigate to="/login" />;
21+
return <Navigate to="/login" replace />;
1422
}
1523

16-
return children;
24+
return <>{children}</>;
1725
};
1826

1927
export default ProtectedRoute;

Diff for: frontend/src/pages/WorkerDetailsPage.tsx

+2-1
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,8 @@ const WorkerDetails: React.FC = () => {
128128
{worker.first_name} {worker.last_name}
129129
</h1>
130130
<div className="text-gray-500">
131-
{worker.trade == "Electrical" ? (<span>Electrician</span>
131+
{worker.trade == "Electrical" ? (
132+
<span>Electrician</span>
132133
) : (
133134
<span>Plumber</span>
134135
)}

Diff for: frontend/tsconfig.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
11
{
22
"compilerOptions": {
3+
"allowSyntheticDefaultImports": true,
4+
"esModuleInterop": true,
35
"target": "ES2020",
46
"useDefineForClassFields": true,
57
"lib": ["ES2020", "DOM", "DOM.Iterable"],
68
"module": "ESNext",
79
"skipLibCheck": true,
810

911
/* Bundler mode */
10-
"moduleResolution": "bundler",
12+
"moduleResolution": "Node",
1113
"allowImportingTsExtensions": true,
1214
"resolveJsonModule": true,
1315
"isolatedModules": true,

0 commit comments

Comments
 (0)