├── .github └── FUNDING.yml ├── .gitignore ├── README.md ├── package-lock.json ├── package.json ├── public ├── favicon.ico ├── index.html ├── logo192.png ├── logo512.png ├── manifest.json └── robots.txt ├── src ├── App.css ├── App.js ├── Login.js ├── Logout.js ├── Profile.js ├── index.css ├── index.js └── logo.svg └── yarn.lock /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | github: carlosazaustre 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🔐 Auth0 en React 2 | 3 | > Ejemplo de funcionamiento de Auth0 para la autenticación de usuarios, utilizando React. 4 | 5 | Código del ejemplo que se ve en el vídeo de Youtube [🔐 Cómo hacer LOGIN y REGISTRO en REACT.js con AUTH0](https://www.youtube.com/watch?v=sTJaHQINpTc) 6 | 7 | [![🔐 Cómo hacer LOGIN y REGISTRO en REACT.js con AUTH0](https://user-images.githubusercontent.com/650752/123842121-b7b92380-d910-11eb-9991-997b28513bf5.png)](https://www.youtube.com/watch?v=sTJaHQINpTc) 8 | 9 | 10 | ## Licencia 11 | 12 | MIT (c) Carlos Azaustre 13 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "auth0-example", 3 | "version": "0.1.0", 4 | "private": true, 5 | "dependencies": { 6 | "@auth0/auth0-react": "^1.4.0", 7 | "@testing-library/jest-dom": "^5.11.4", 8 | "@testing-library/react": "^11.1.0", 9 | "@testing-library/user-event": "^12.1.10", 10 | "react": "^17.0.2", 11 | "react-dom": "^17.0.2", 12 | "react-scripts": "4.0.3", 13 | "web-vitals": "^1.0.1" 14 | }, 15 | "scripts": { 16 | "start": "react-scripts start", 17 | "build": "react-scripts build", 18 | "test": "react-scripts test", 19 | "eject": "react-scripts eject" 20 | }, 21 | "eslintConfig": { 22 | "extends": [ 23 | "react-app", 24 | "react-app/jest" 25 | ] 26 | }, 27 | "browserslist": { 28 | "production": [ 29 | ">0.2%", 30 | "not dead", 31 | "not op_mini all" 32 | ], 33 | "development": [ 34 | "last 1 chrome version", 35 | "last 1 firefox version", 36 | "last 1 safari version" 37 | ] 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carlosazaustre/react-auth0/c0905845ebf523b17087f1a58200053014b60e50/public/favicon.ico -------------------------------------------------------------------------------- /public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 17 | 18 | 27 | React App 28 | 29 | 30 | 31 |
32 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /public/logo192.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carlosazaustre/react-auth0/c0905845ebf523b17087f1a58200053014b60e50/public/logo192.png -------------------------------------------------------------------------------- /public/logo512.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/carlosazaustre/react-auth0/c0905845ebf523b17087f1a58200053014b60e50/public/logo512.png -------------------------------------------------------------------------------- /public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "React App", 3 | "name": "Create React App Sample", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | }, 10 | { 11 | "src": "logo192.png", 12 | "type": "image/png", 13 | "sizes": "192x192" 14 | }, 15 | { 16 | "src": "logo512.png", 17 | "type": "image/png", 18 | "sizes": "512x512" 19 | } 20 | ], 21 | "start_url": ".", 22 | "display": "standalone", 23 | "theme_color": "#000000", 24 | "background_color": "#ffffff" 25 | } 26 | -------------------------------------------------------------------------------- /public/robots.txt: -------------------------------------------------------------------------------- 1 | # https://www.robotstxt.org/robotstxt.html 2 | User-agent: * 3 | Disallow: 4 | -------------------------------------------------------------------------------- /src/App.css: -------------------------------------------------------------------------------- 1 | .App { 2 | text-align: center; 3 | } 4 | 5 | .App-logo { 6 | height: 40vmin; 7 | pointer-events: none; 8 | } 9 | 10 | @media (prefers-reduced-motion: no-preference) { 11 | .App-logo { 12 | animation: App-logo-spin infinite 20s linear; 13 | } 14 | } 15 | 16 | .App-header { 17 | background-color: #282c34; 18 | min-height: 100vh; 19 | display: flex; 20 | flex-direction: column; 21 | align-items: center; 22 | justify-content: center; 23 | font-size: calc(10px + 2vmin); 24 | color: white; 25 | } 26 | 27 | .App-link { 28 | color: #61dafb; 29 | } 30 | 31 | @keyframes App-logo-spin { 32 | from { 33 | transform: rotate(0deg); 34 | } 35 | to { 36 | transform: rotate(360deg); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /src/App.js: -------------------------------------------------------------------------------- 1 | import { useAuth0 } from "@auth0/auth0-react"; 2 | 3 | import { LoginButton } from "./Login"; 4 | import { LogoutButton } from "./Logout"; 5 | import { Profile } from "./Profile"; 6 | import logo from "./logo.svg"; 7 | import "./App.css"; 8 | 9 | function App() { 10 | const { isAuthenticated } = useAuth0(); 11 | 12 | return ( 13 |
14 |
15 | logo 16 | {isAuthenticated ? ( 17 | <> 18 | 19 | 20 | 21 | ) : ( 22 | 23 | )} 24 |
25 |
26 | ); 27 | } 28 | 29 | export default App; 30 | -------------------------------------------------------------------------------- /src/Login.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useAuth0 } from "@auth0/auth0-react"; 3 | 4 | export const LoginButton = () => { 5 | const { loginWithRedirect } = useAuth0(); 6 | 7 | return ; 8 | }; 9 | -------------------------------------------------------------------------------- /src/Logout.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useAuth0 } from "@auth0/auth0-react"; 3 | 4 | export const LogoutButton = () => { 5 | const { logout } = useAuth0(); 6 | 7 | return ( 8 | 11 | ); 12 | }; 13 | -------------------------------------------------------------------------------- /src/Profile.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import { useAuth0 } from "@auth0/auth0-react"; 3 | 4 | export const Profile = () => { 5 | const { user, isAuthenticated, isLoading } = useAuth0(); 6 | 7 | if (isLoading) { 8 | return
Loading...
; 9 | } 10 | 11 | return ( 12 | isAuthenticated && ( 13 |
14 | {user.name} 15 |

{user.name}

16 |

Email: {user.email}

17 |
18 | ) 19 | ); 20 | }; 21 | -------------------------------------------------------------------------------- /src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen', 4 | 'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue', 5 | sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New', 12 | monospace; 13 | } 14 | -------------------------------------------------------------------------------- /src/index.js: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import ReactDOM from "react-dom"; 3 | import { Auth0Provider } from "@auth0/auth0-react"; 4 | import App from "./App"; 5 | import "./index.css"; 6 | 7 | ReactDOM.render( 8 | 9 | 14 | 15 | 16 | , 17 | document.getElementById("root") 18 | ); 19 | -------------------------------------------------------------------------------- /src/logo.svg: -------------------------------------------------------------------------------- 1 | --------------------------------------------------------------------------------