{"id":15284472,"url":"https://github.com/scarmuega/react-use-auth0","last_synced_at":"2025-04-12T23:34:49.086Z","repository":{"id":34932018,"uuid":"191937251","full_name":"scarmuega/react-use-auth0","owner":"scarmuega","description":"Auth0 React integration using context and hooks","archived":false,"fork":false,"pushed_at":"2023-03-04T03:55:39.000Z","size":694,"stargazers_count":3,"open_issues_count":12,"forks_count":1,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-02-15T06:47:10.207Z","etag":null,"topics":["auth0","react","react-hooks"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/scarmuega.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-06-14T12:11:51.000Z","updated_at":"2023-03-28T09:46:57.000Z","dependencies_parsed_at":"2024-10-14T15:01:10.154Z","dependency_job_id":"e133f9b3-667a-488c-ae6a-ed219ea29724","html_url":"https://github.com/scarmuega/react-use-auth0","commit_stats":{"total_commits":19,"total_committers":2,"mean_commits":9.5,"dds":"0.052631578947368474","last_synced_commit":"3e97f5d19d24804605b26ac549e6c37d25015a1c"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarmuega%2Freact-use-auth0","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarmuega%2Freact-use-auth0/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarmuega%2Freact-use-auth0/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/scarmuega%2Freact-use-auth0/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/scarmuega","download_url":"https://codeload.github.com/scarmuega/react-use-auth0/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239994002,"owners_count":19730780,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["auth0","react","react-hooks"],"created_at":"2024-09-30T14:57:08.023Z","updated_at":"2025-02-22T12:30:36.931Z","avatar_url":"https://github.com/scarmuega.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"useAuth0\n========\n\nThis library hides all the boilerplate code required to authenticate a React SPA using Auth0. Most of the code is borrowed from the [official Auth0 tutorial](https://auth0.com/docs/quickstart/spa/react/01-login), but also adds some nice-to-have utilities for common use-cases.\n\nInstallation\n------------\n\nto install the library, do as usual:\n\n```\nnpm install --save react-use-auth0\n```\n\nUsage\n-----\n\nAs the name implies, it uses react hooks. Here's a snippet of how to use the `useAuth0` and the `Auth0Setup` HoC that provides the context for the children:\n\n```tsx\nimport React from \"react\";\nimport * as ReactDOM from \"react-dom\";\nimport { Auth0Setup, useAuth0, useAuth0Token, useAuth0User } from \"../index\";\n\nfunction PrivateData() {\n    const user = useAuth0User();\n    const token = useAuth0Token();\n    return (\n        \u003cdiv\u003e\n            {user.result \u0026\u0026 \u003cspan\u003eyour user is: {JSON.stringify(user.result)}\u003c/span\u003e}\n            {token.result \u0026\u0026 \u003cbutton onClick={() =\u003e console.log(token.result)}\u003elog token\u003c/button\u003e}\n        \u003c/div\u003e\n    );\n}\n\nfunction LogoutButton() {\n    const auth = useAuth0();\n    return \u003cbutton onClick={() =\u003e auth.logout()}\u003eLogout\u003c/button\u003e\n}\n\nfunction LoginButton() {\n    const auth = useAuth0();\n    return \u003cbutton onClick={() =\u003e auth.loginWithRedirect({ appState: { button: \"button_1\" } })}\u003eLogin\u003c/button\u003e\n}\n\nfunction App() {\n    const auth = useAuth0();\n    return (\n        \u003c\u003e\n            {auth.isAuthenticated \u0026\u0026 \u003cPrivateData /\u003e}\n            {!auth.isAuthenticated ? \u003cLoginButton /\u003e : \u003cLogoutButton /\u003e}\n        \u003c/\u003e\n    );\n}\n\n// A function that routes the user to the right place\n// after login\nconst onRedirectCallback = (appState: any) =\u003e {\n    window.history.replaceState({}, document.title, window.location.pathname);\n    const button = appState \u0026\u0026 appState.button;\n    console.log(`logged in from button: ${button}`);\n};\n\nReactDOM.render(\n    \u003cAuth0Setup\n        domain=\"my-tenant.auth0.com\"\n        clientId=\"client-id-provided-by-auth0\"\n        redirectUri=\"http://localhost:3001\"\n        onRedirectCallback={onRedirectCallback}\n        scope=\"openid\"\n    \u003e\n        \u003cApp /\u003e\n    \u003c/Auth0Setup\u003e,\n    document.getElementById(\"root\")\n);\n```\n\nDemo \n-----\nYou can find a very basic example in the `/demo` folder. To run it, first change your tenant and client id inside `demo.tsx` and then start the server by running `npm run start`","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarmuega%2Freact-use-auth0","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fscarmuega%2Freact-use-auth0","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fscarmuega%2Freact-use-auth0/lists"}