Spaces:
Running
Running
File size: 953 Bytes
78e55c0 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
import { useAuth0 } from "@auth0/auth0-react";
function App() {
const {
isLoading, // Loading state, the SDK needs to reach Auth0 on load
isAuthenticated,
error,
loginWithRedirect: login, // Starts the login flow
logout: auth0Logout, // Starts the logout flow
user, // User profile
} = useAuth0();
const signup = () =>
login({ authorizationParams: { screen_hint: "signup" } });
const logout = () =>
auth0Logout({ logoutParams: { returnTo: window.location.origin } });
if (isLoading) return "Loading...";
return isAuthenticated ? (
<>
<p>Logged in as {user.email}</p>
<h1>User Profile</h1>
<pre>{JSON.stringify(user, null, 2)}</pre>
<button onClick={logout}>Logout</button>
</>
) : (
<>
{error && <p>Error: {error.message}</p>}
<button onClick={signup}>Signup</button>
<button onClick={login}>Login</button>
</>
);
}
export default App;
|