Skip to content

Commit

Permalink
Refactor auth
Browse files Browse the repository at this point in the history
Fixes #140
  • Loading branch information
mpapenbr authored and mpapenbr committed Apr 2, 2022
1 parent 1eda474 commit 818238b
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 102 deletions.
43 changes: 0 additions & 43 deletions src/pages/External.tsx

This file was deleted.

27 changes: 0 additions & 27 deletions src/pages/Home.tsx

This file was deleted.

30 changes: 0 additions & 30 deletions src/pages/Login.tsx

This file was deleted.

2 changes: 1 addition & 1 deletion src/routes/auth.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const AuthProvider = ({ children }) => {
};

const tokenLogger = (tokens: unknown) => {
console.log("onKeycloakTokens", tokens);
// console.log("onKeycloakTokens", tokens);
};

// const handleLogin = useCallback(() => {
Expand Down
19 changes: 18 additions & 1 deletion src/routes/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { useKeycloak } from "@react-keycloak/web";
import * as React from "react";
import { BrowserRouter, Route, Routes } from "react-router-dom";
import { BrowserRouter, Navigate, Route, Routes, useLocation } from "react-router-dom";
import { EXT_LOAD_ID } from "../constants";
import TabContainer from "../container/tabContainer";
import { useAuth } from "./auth";
import { PrivateRoute } from "./utils";
Expand All @@ -10,6 +11,20 @@ const Home = () => {
if (!name) return <p>Please use the login button.</p>;
return <TabContainer />;
};

const External = () => {
const location = useLocation();

const regex = new RegExp("id=(?<myid>[a-f0-9\\-]{36})");
const results = regex.exec(location.search);
if (results === null) {
return <p>Invalid query parameters.</p>;
}

window.sessionStorage.setItem(EXT_LOAD_ID, results[1]);
return <Navigate to="/home" replace />;
};

const Unknown = () => {
return <p>NotMatched route</p>;
};
Expand All @@ -25,6 +40,7 @@ export const AppRouter = () => {
<BrowserRouter>
<Routes>
<Route path="" element={<Home />} />
<Route path="ext" element={<External />} />

<Route
path="home"
Expand All @@ -38,6 +54,7 @@ export const AppRouter = () => {
</Routes>
</BrowserRouter>
);
// http://localhost:3000/ext?id=caa3d195-9ed0-47e2-84a8-db008f76358c

// return (
// <Router>
Expand Down

0 comments on commit 818238b

Please sign in to comment.