{"id":19982447,"url":"https://github.com/netlify/netlify-graph-auth","last_synced_at":"2025-05-04T05:32:26.436Z","repository":{"id":41330521,"uuid":"452862188","full_name":"netlify/netlify-graph-auth","owner":"netlify","description":null,"archived":false,"fork":false,"pushed_at":"2023-05-28T13:08:23.000Z","size":77,"stargazers_count":4,"open_issues_count":1,"forks_count":3,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-05-01T00:30:58.507Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/netlify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-01-27T22:13:35.000Z","updated_at":"2022-10-21T00:28:36.000Z","dependencies_parsed_at":"2022-08-10T01:54:27.138Z","dependency_job_id":null,"html_url":"https://github.com/netlify/netlify-graph-auth","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fnetlify-graph-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fnetlify-graph-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fnetlify-graph-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/netlify%2Fnetlify-graph-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/netlify","download_url":"https://codeload.github.com/netlify/netlify-graph-auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252293082,"owners_count":21724960,"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":[],"created_at":"2024-11-13T04:11:25.964Z","updated_at":"2025-05-04T05:32:26.175Z","avatar_url":"https://github.com/netlify.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Netlify Graph Authentication Helpers for browsers\nBefore you can make queries on behalf of your users against 3rd-party services like Stripe,\nthe client needs to grant access to your app through an OAuth flow.\n\nNetlify Graph provides an easy-to-use javascript auth library to manage\nauthenticating your clients with 3rd-party services.\n\n## Install\nAdd the netlify-graph-auth library to your app:\n\n```\nnpm install netlify-graph-auth\n```\n\n## Create an Auth Client\n\nFor our example, we'll log in to GitHub.\n\nFirst, we'll construct a new NetlifyGraphAuth instance with our siteId.\n\n```javascript\nimport NetlifyGraphAuth from 'netlify-graph-auth';\nimport process from 'process';\n\nconst auth = new NetlifyGraphAuth({\n  siteId: process.env.SITE_ID,\n});\n```\n\nThe NetlifyGraphAuth client has 3 methods, `isLoggedIn`, `login`, `logout`.\n\n## Check if the user is loggedIn\n\nThe `isLoggedIn` method takes a service name as its only argument and\nwill return a promise with a boolean indicating if the user is logged\nin to that service.\n\n```javascript\nconst isLoggedIn = await auth.isLoggedIn('github');\nif (isLoggedIn) {\n  console.log('Already logged in to GitHub');\n} else {\n  console.log('Not logged in to GitHub.');\n}\n```\n\n## Log the user in\n\nThe `login` method takes a service name as its only argument and will\ntake the client through the OAuth login flow for the service and\nreturn a promise that resolves after the client finishes the flow.\n\nAfter the client finishes, you can call `isLoggedIn` again to check if the\nuser successfully made it through the flow.\n\n```javascript\ntry {\n  // Prompt the user to log into GitHub\n  await auth.login('github');\n\n  // Check to see if they logged in successfully\n  const isLoggedIn = await auth.isLoggedIn('github');\n\n  if (isLoggedIn) {\n    console.log('Successfully logged in to GitHub');\n  } else {\n    console.log('Did not grant auth for GitHub');\n  }\n} catch (error) {\n  console.error('Problem logging in', error);\n}\n```\n\n## Log the user out\n\nThe `logout` method takes a service name as its only argument and will\nlog the client out and return a promise wrapping an object with a\n`result` key whose value is either 'success' or 'failure' to indicate\nwhether the user is still logged in.\n\n```javascript\nconst response = await auth.logout('github');\n\nif (response.result === 'success') {\n  console.log('Logout succeeded');\n} else {\n  console.log('Logout failed');\n}\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify%2Fnetlify-graph-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnetlify%2Fnetlify-graph-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnetlify%2Fnetlify-graph-auth/lists"}