{"id":15931222,"url":"https://github.com/zentered/auth0-solid-start","last_synced_at":"2025-03-24T18:31:45.725Z","repository":{"id":58775151,"uuid":"533621072","full_name":"zentered/auth0-solid-start","owner":"zentered","description":"Auth0 authentication for Solid SSR","archived":false,"fork":false,"pushed_at":"2024-09-26T20:16:02.000Z","size":1290,"stargazers_count":24,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-16T01:46:35.474Z","etag":null,"topics":["auth0","solid-start","solidjs"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/zentered.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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":"2022-09-07T05:35:58.000Z","updated_at":"2025-01-12T22:19:40.000Z","dependencies_parsed_at":"2023-01-29T02:31:38.807Z","dependency_job_id":"aa7439db-c69c-4549-82e7-9de4f9ec341d","html_url":"https://github.com/zentered/auth0-solid-start","commit_stats":{"total_commits":65,"total_committers":6,"mean_commits":"10.833333333333334","dds":"0.36923076923076925","last_synced_commit":"64721d001093a4a173f55ee51c997a5c0bc4ad17"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentered%2Fauth0-solid-start","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentered%2Fauth0-solid-start/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentered%2Fauth0-solid-start/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zentered%2Fauth0-solid-start/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zentered","download_url":"https://codeload.github.com/zentered/auth0-solid-start/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245328267,"owners_count":20597396,"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","solid-start","solidjs"],"created_at":"2024-10-07T01:04:31.466Z","updated_at":"2025-03-24T18:31:45.424Z","avatar_url":"https://github.com/zentered.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Auth0 Solid Start (SSR compatible) [DEPRECATED]\n\n## Deprecation Notice\n\nI don't have the time to maintain this module any longer. If you're interested in taking over, please let me know.\n\nIn the meantime, [Auth.js](https://authjs.dev/reference/solid-start) seems like a good solution.\n\n\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\".github/assets/auth0-solid-start.jpg\"\u003e\n\u003c/p\u003e\n\n[![Publish](https://github.com/zentered/auth0-solid-start/actions/workflows/publish.yml/badge.svg)](https://github.com/zentered/auth0-solid-start/actions/workflows/publish.yml)\n\nThis is a fully functional library to add [Auth0](https://auth0.com) OAuth\nAuthentication to a [Solid-Start](https://github.com/solidjs/solid-start) App.\n\nYou'll need to sign up and create an Auth0 Application to use this library. The\ncredentials are stored in an `.env` file (see [.env.example](./env.example)).\n\nThis work is inspired by\n\n- Ryan Turnquist [solid-auth0](https://github.com/rturnq/solid-auth0)\n- Sergio Xalambrí\n  [remix-auth-oauth2](https://github.com/sergiodxa/remix-auth-oauth2)\n\n## How it works\n\nThis library is intended to be used on `root` level of your Solid-Start App. It\nprovides an authentication context for the entire App. Users/passwords etc. are\nall stored in Auth0, we use the Universal Login Experience to authenticate users\nand get a `code`, which we can exchange for an `access_token`. The\n`access_token` is a valid JWT token and can be used to authenticate requests to\nyour API / GraphQL /etc.\n\nThe callback URL is set to `/auth/callback`, so you need to create an API route\nin `src/routes/auth/callback.js/ts`. The code can be found below.\n\n```mermaid\nflowchart\n    A[Browser] --\u003e B[Initial Render/SSR]\n    B{Valid Session Cookie exists?} --\u003e |Yes| C\n    C[Set Signals \u0026 Render App]\n    B --\u003e |No| D[Redirect to Auth0 Universal Login]\n    D --\u003e E[Callback to `/auth/callback` with `code` \u0026 `state`]\n    E --\u003e F[Exchange `code` for `access_token`]\n    F --\u003e G[Get User Info with access_token]\n    G --\u003e H[Set Signals \u0026 Session Cookie]\n    H --\u003e C[Render App]\n\n```\n\n## Multi Tenant Mode\n\nMulti Tenant Mode can be used with\n[Auth0 Organizations](https://auth0.com/docs/manage-users/organizations). You'll\nhave to pass an organization object into the Auth0 context with an `id`. We\nrecommend using the same schema as Auth0.\n\nSet `VITE_AUTH0_REWRITE_REDIRECT=true` in `.env`\n\n## Usage\n\n### Environment Variables\n\nSee [.env.example](./env.example)\n\n- `VITE_AUTH0_REWRITE_REDIRECT` requires the Auth0 Organization setup\n- `VITE_AUTH0_OFFLINE_ACCESS` requires the Auth0 API to be configured with\n  offline access\n- `VITE_AUTH0_LOGOUT_URL` the logout url (a server-side route, ie\n  http://localhost:8080/auth/logout)\n\n### vite.config.ts/js\n\nThere's an issue with vite throwing `process` is undefined errors when the\nsession is loaded on the client. To fix this, add the following to your\n`vite.config.ts/js`:\n\n```js\ndefine: {\n    'process.env': process.env\n  },\n```\n\n### root.jsx / .tsx\n\nIn `root.tsx` to enforce authentication on all pages:\n\n```jsx\nimport { Show, Suspense } from 'solid-js'\nimport { isServer } from 'solid-js/web'\nimport { ErrorBoundary, FileRoutes, Routes } from 'solid-start'\nimport { Auth0, useAuth0 } from '@zentered/auth0-solid-start'\n\nconst GraphQLProvider = () =\u003e {} // let's assume you want to authenticate graphql requests with your JWT\n\nfunction Login(props) {\n  return (\n    \u003cdiv\u003e\n      \u003cp\u003eSign in\u003c/p\u003e\n      \u003cdiv\u003e\n        \u003cdiv\u003e\n          \u003ca onClick={() =\u003e props.auth0.authorize()} type=\"button\"\u003e\n            Log In\n          \u003c/a\u003e\n        \u003c/div\u003e\n      \u003c/div\u003e\n    \u003c/div\u003e\n  )\n}\n\nfunction SiteRequiresAuth(props) {\n  const auth0 = useAuth0()\n\n  if (!auth0.isAuthenticated() \u0026\u0026 !isServer) {\n    auth0.login()\n  }\n\n  return (\n    \u003c\u003e\n      \u003cShow when={auth0.isInitialized()}\u003e\n        \u003cShow when={auth0.isAuthenticated()} fallback={\u003cLogin auth0={auth0} /\u003e}\u003e\n          \u003cShow when={auth0.accessToken()}\u003e\n            \u003cGraphQLProvider auth0={auth0}\u003e{props.children}\u003c/GraphQLProvider\u003e\n          \u003c/Show\u003e\n        \u003c/Show\u003e\n      \u003c/Show\u003e\n    \u003c/\u003e\n  )\n}\n\nexport default function Root() {\n  return (\n    // ...\n    \u003cSuspense\u003e\n      \u003cErrorBoundary\u003e\n        \u003cAuth0\n          domain={import.meta.env.VITE_AUTH0_DOMAIN}\n          clientId={import.meta.env.VITE_AUTH0_CLIENT_ID}\n          audience={import.meta.env.VITE_AUTH0_AUDIENCE}\n          redirectUri={import.meta.env.VITE_AUTH0_REDIRECT_URI}\n          logoutUrl={`${import.meta.env.VITE_BASE_URL}/auth/logout`}\n          // organization={organization} // uncomment if you use auth0 organizations\n        \u003e\n          \u003cSiteRequiresAuth\u003e\n            \u003cRoutes\u003e\n              \u003cFileRoutes /\u003e\n            \u003c/Routes\u003e\n          \u003c/SiteRequiresAuth\u003e\n        \u003c/Auth0\u003e\n      \u003c/ErrorBoundary\u003e\n    \u003c/Suspense\u003e\n    // ...\n  )\n}\n```\n\n### With Organization Invitation\n\nIf you use Auth0 Organizations, you can pass through the `invitation`,\n`organization` and `organization_name` query params to the Auth0 Universal Login\nExperience. This will load the sign-up instead of the login form:\n\n```jsx\n// root.jsx/tsx\nconst [searchParams] = useSearchParams()\n\nif (searchParams.invitation) {\n  auth0.setInvitation(\n    searchParams.invitation,\n    searchParams.organization,\n    searchParams.organization_name\n  )\n}\n```\n\n### Logout\n\nThe logout happens in 3 steps:\n\n1. User clicks \"Sign out\" and starts the process\n2. `logout` function on the Auth0 Provider is triggered that generates an\n   [auth0 logout url](https://auth0.com/docs/authenticate/login/logout/log-users-out-of-applications)\n3. Auth0 redirects back to the \"logout url\" which clears the session.\n\nThere are two parts: the logout function in the auth0 provider and the \"api\"\nroute (ie `/auth/logout`), see below.\n\nIn any component/page where you want the \"Sign out\" link:\n\n```jsx\nimport { useAuth0 } from '@zentered/auth0-solid-start'\nimport { Link } from '@solidjs/router'\n\nexport default function Component() {\n  const auth0 = useAuth0()\n  const [, logout] = createRouteAction(async () =\u003e {\n    await auth0.logout()\n  })\n\n  \u003cLink\n    href=\"#\"\n    class={`button`}\n    onClick={() =\u003e logout()}\n  \u003e\n    Sign Out\n  \u003c/Link\u003e\n}\n\n```\n\n### API\n\n#### Callback\n\n`routes/auth/callback.js|ts`:\n\n```js\nimport fn from '@zentered/auth0-solid-start/api/callback'\n\nexport async function GET({ request }) {\n  return fn(request)\n}\n```\n\n#### Logout API\n\n`routes/auth/logout.js|ts`:\n\n```js\nimport fn from '@zentered/auth0-solid-start/api/logout'\n\nexport function GET({ request }) {\n  return fn(request)\n}\n```\n\n## Development\n\nYou can fork/clone this repository and link it into your working project with\n`pnpm link`:\n\n```bash\ncd auth0-solid-start\npnpm link\n\ncd ../your-project\npnpm link @zentered/auth0-solid-start ../../auth0-solid-start\n```\n\nInstead of using the `npm` version you're now working with a local copy. Changes\nin the `auth0-solid-start` folder _should_ restart the app.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentered%2Fauth0-solid-start","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzentered%2Fauth0-solid-start","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzentered%2Fauth0-solid-start/lists"}