feat(auth0) add Loading component and Routes
This commit is contained in:
parent
9e55024b00
commit
f1d669579e
|
@ -1,8 +1,10 @@
|
|||
import React from 'react';
|
||||
import { Route, Routes } from "react-router-dom";
|
||||
import { useAuth0 } from '@auth0/auth0-react';
|
||||
|
||||
import NavBar from "./components/nav-bar";
|
||||
import Loading from "./components/loading";
|
||||
import Profile from "./pages/profile";
|
||||
import Home from './pages/home';
|
||||
export default function App() {
|
||||
const { isLoading } = useAuth0();
|
||||
|
@ -13,8 +15,10 @@ export default function App() {
|
|||
<div>
|
||||
<NavBar />
|
||||
<div>
|
||||
<h1>Auth0 with React.js</h1>
|
||||
<Home />
|
||||
<Routes>
|
||||
<Route path="/" element={<Home/>} />
|
||||
<Route path="/profile" element={<Profile/>} />
|
||||
</Routes>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -1,8 +1,18 @@
|
|||
import {NavLink} from "react-router-dom";
|
||||
import React from "react";
|
||||
|
||||
const MainNav = () => (
|
||||
<div>
|
||||
MainNav loading...
|
||||
<NavLink
|
||||
to="/"
|
||||
>
|
||||
Home
|
||||
</NavLink>
|
||||
<NavLink
|
||||
to="/profile"
|
||||
>
|
||||
Profile
|
||||
</NavLink>
|
||||
</div>
|
||||
);
|
||||
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import React from 'react';
|
||||
|
||||
import { useAuth0, withAuthenticationRequired } from '@auth0/auth0-react';
|
||||
import Loading from '../components/loading';
|
||||
|
||||
const Profile = () => {
|
||||
const { user } = useAuth0();
|
||||
const { name, picture, email } = user;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<div>
|
||||
<div>
|
||||
<img
|
||||
src={picture}
|
||||
alt="Profile"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<h2>{name}</h2>
|
||||
<p>{email}</p>
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<pre>
|
||||
{JSON.stringify(user, null, 2)}
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
export default withAuthenticationRequired(Profile, {
|
||||
onRedirecting: () => <Loading />,
|
||||
});
|
Loading…
Reference in New Issue