fix OAuth2 issue

This commit is contained in:
h z
2024-12-04 08:03:14 +00:00
parent 18a84123d3
commit 321dea202d
7 changed files with 23 additions and 12 deletions

View File

@@ -3,10 +3,9 @@
<head> <head>
<meta charset="UTF-8"> <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>React x Project</title> <title>Hangman Lab</title>
</head> </head>
<body> <body>
<h2>wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww</h2>
<div id="root"></div> <div id="root"></div>
</body> </body>
</html> </html>

View File

@@ -4,6 +4,7 @@ import MainNavigation from "./components/MainNavigation";
import SideNavigation from "./components/SideNavigation"; import SideNavigation from "./components/SideNavigation";
import MarkdownContent from "./components/MarkdownContent"; import MarkdownContent from "./components/MarkdownContent";
import "./App.css"; import "./App.css";
import Callback from "./Callback";
const App = () => { const App = () => {
return ( return (
@@ -16,6 +17,8 @@ const App = () => {
<Routes> <Routes>
<Route path="/" element={<h1>Welcome to My React Project</h1>} /> <Route path="/" element={<h1>Welcome to My React Project</h1>} />
<Route path="/markdown/:id" element={<MarkdownContent />} /> <Route path="/markdown/:id" element={<MarkdownContent />} />
<Route path="/callback" element={<Callback />} />
<Route path="/test" element={<h1>TEST</h1>}></Route>
</Routes> </Routes>
</main> </main>
</div> </div>

View File

@@ -21,7 +21,10 @@ const AuthProvider = ({ children }) => {
}); });
}, [userManager]); }, [userManager]);
const login = () => userManager.signinRedirect(); const login = () => {
console.log('triggered');
userManager.signinRedirect().catch((err) => {console.log(err)});
}
const logout = () => userManager.signoutRedirect(); const logout = () => userManager.signoutRedirect();
return ( return (

View File

@@ -16,16 +16,16 @@ const MainNavigation = () => {
{ user && user.profile ? ( { user && user.profile ? (
<div> <div>
<h1>{user.profile.name}</h1> <h1>{user.profile.name}</h1>
<button onClick={logout}>Logout</button> <Link to="/logout">Logout</Link>
</div> </div>
) : ( ) : (
<li>
<button onClick={login}>Login</button> <button onClick={login}>Login</button>
</li>
) )
} }
<li>
<Link to="/login">Login</Link>
</li>
<li> <li>
<a href="https://mail.hangman-lab.top" target="_blank" rel="noopener noreferrer"> <a href="https://mail.hangman-lab.top" target="_blank" rel="noopener noreferrer">
MailBox MailBox

View File

@@ -1,8 +1,13 @@
import React from "react"; import React from "react";
import ReactDOM from "react-dom/client"; import ReactDOM from "react-dom/client";
import App from "./App"; import App from "./App";
import AuthProvider from "./AuthProvider";
//ReactDOM.render(<App />, document.getElementById("root")); //ReactDOM.render(<App />, document.getElementById("root"));
const root = ReactDOM.createRoot(document.getElementById("root")); const root = ReactDOM.createRoot(document.getElementById("root"));
root.render(<App />); root.render(
<AuthProvider>
<App />
</AuthProvider>
);

View File

@@ -1,6 +1,6 @@
export const oidcConfig = { export const oidcConfig = {
authority: "https://login.hangman-lab.top/auth/realms/myrealm", authority: "https://login.hangman-lab.top/realms/Hangman-Lab",
client_id: "your-client-id", client_id: "labdev",
redirect_uri: "http://localhost:3000/callback", redirect_uri: "http://localhost:3000/callback",
post_logout_redirect_uri: "http://localhost:3000", post_logout_redirect_uri: "http://localhost:3000",
response_type: "code", response_type: "code",

View File

@@ -34,5 +34,6 @@ module.exports = {
port: 3000, port: 3000,
open: true, open: true,
hot: true, hot: true,
historyApiFallback: true,
} }
}; };