{"id":19964967,"url":"https://github.com/arunoda/use-magic-link","last_synced_at":"2025-05-03T23:30:40.463Z","repository":{"id":42831679,"uuid":"265532233","full_name":"arunoda/use-magic-link","owner":"arunoda","description":"Simple auth setup for your React app in few minutes with Magic Link.","archived":false,"fork":false,"pushed_at":"2023-01-06T06:28:18.000Z","size":586,"stargazers_count":111,"open_issues_count":8,"forks_count":6,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-07T23:04:43.983Z","etag":null,"topics":["authentication","magiclink","react"],"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/arunoda.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}},"created_at":"2020-05-20T10:36:15.000Z","updated_at":"2024-12-21T20:21:27.000Z","dependencies_parsed_at":"2023-02-05T13:02:18.755Z","dependency_job_id":null,"html_url":"https://github.com/arunoda/use-magic-link","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunoda%2Fuse-magic-link","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunoda%2Fuse-magic-link/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunoda%2Fuse-magic-link/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/arunoda%2Fuse-magic-link/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/arunoda","download_url":"https://codeload.github.com/arunoda/use-magic-link/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252269026,"owners_count":21721239,"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":["authentication","magiclink","react"],"created_at":"2024-11-13T02:26:27.545Z","updated_at":"2025-05-03T23:30:39.989Z","avatar_url":"https://github.com/arunoda.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# use-magic-link\n\nSimple auth setup for your React app in few minutes with [Magic Link](https://magic.link).\n\n[Read this guide](https://arunoda.me/blog/simple-auth-setup-for-your-react-app)\n\n\u003ca href=\"https://arunoda.me/blog/simple-auth-setup-for-your-react-app\"\u003e\u003cimg src=\"https://img.youtube.com/vi/9kC24Mr0wHg/maxresdefault.jpg\" width=\"600px\"/\u003e\u003c/a\u003e\n\n## Install the React Hook\n\n```\nyarn add use-magic-link\n```\n\n## Example\n\nHere's how this React hook works:\n\n```js\n// Get this with \"yarn add use-magic-link\"\nimport useMagicLink from 'use-magic-link'\n\nexport default function Home() {\n  // create the hook\n  const auth = useMagicLink('\u003cPublishable Key\u003e');\n\n  function loginNow() {\n    const email = prompt('Enter your email');\n    auth.login(email);\n  }\n\n  function getContent() {\n    // Show a loading screen until we detect the login-state\n    if (auth.loading || auth.loggingIn || auth.loggingOut) {\n      return '...'\n    }\n\n    // Show this, if logged in\n    if (auth.loggedIn) {\n      return (\n        \u003cdiv\u003e\n          You are logged-in.\n          \u003cbr/\u003e\n          \u003cbutton onClick={() =\u003e auth.logout()}\u003eLogout\u003c/button\u003e\n        \u003c/div\u003e\n      )\n    }\n\n    // Show this, if not logged-in\n    return (\n      \u003cdiv\u003e\n        \u003cbutton onClick={loginNow}\u003eLogin Now\u003c/button\u003e\n      \u003c/div\u003e\n    )\n  }\n\n  return (\n    \u003cdiv className=\"container\"\u003e\n      \u003cmain\u003e\n        \u003ch1\u003eNext.js Bank\u003c/h1\u003e\n        \u003cdiv className=\"content\"\u003e{getContent()}\u003c/div\u003e\n      \u003c/main\u003e\n    \u003c/div\u003e\n  )\n}\n```\n\n## API\n\nYou will get an auth object after you call the `use-magic-link` React hook. \n\n\u003e Make sure to call this inside a functional component or inside another React hook.\n\n```\nimport useMagicLink from 'use-magic-link'\n\n// inside a functional component\nconst auth = useMagicLink('\u003cPublishable Key\u003e')\n```\n\n\u003e You can get the `\u003cPublishable Key\u003e` by logging into the [Magic Link dashboard](https://magic.link/).\n\nHere are the properties of `auth`:\n\n### auth.loading\n\nIt will be `true`, until we load additional libraries and check the current login state.\n\n### auth.loggedIn\n\nIt will be `true`, if we are loggedIn, otherwise `false`.\n\n### auth.loggingIn\n\nIt will be `true`, once we start the login process.\n\n### auth.loggingOut\n\nIt will be `true`, once we start the logout process.\n\n### auth.error\n\nStore the error object, if something goes wrong.\n\n### auth.login(email)\n\nYou can start the login process by passing a valid email.\n\n### auth.logout()\n\nYou can start the logout process.\n\n### auth.fetch\n\nAn instance of `fetch`, which automatically includes the Magic Link token. You can use this to call any API which uses `@magic-sdk/admin` NPM module to authenticate the request.\n\n[Read this guide for more information](https://arunoda.me/blog/simple-auth-setup-for-your-react-app)\n\n### auth.magic\n\nThe underline Magic Link API client. Read Magic Link [documentation](https://docs.magic.link/) on how to use it.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farunoda%2Fuse-magic-link","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Farunoda%2Fuse-magic-link","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Farunoda%2Fuse-magic-link/lists"}