{"id":24488684,"url":"https://github.com/thesmartmonkey/simple-passwordless-auth","last_synced_at":"2025-03-15T00:30:50.404Z","repository":{"id":271105877,"uuid":"912348800","full_name":"TheSmartMonkey/simple-passwordless-auth","owner":"TheSmartMonkey","description":"A lightweight and simple library for passwordless authentication. Built to help you get things done quickly and securely","archived":false,"fork":false,"pushed_at":"2025-01-13T22:27:33.000Z","size":230,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T16:36:17.356Z","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":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TheSmartMonkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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":"2025-01-05T10:26:06.000Z","updated_at":"2025-01-13T22:27:37.000Z","dependencies_parsed_at":"2025-01-05T15:27:29.153Z","dependency_job_id":"60c6624a-9e1c-4cd7-b661-2f90780fb62b","html_url":"https://github.com/TheSmartMonkey/simple-passwordless-auth","commit_stats":null,"previous_names":["thesmartmonkey/simple-passwordless-auth"],"tags_count":0,"template":false,"template_full_name":"TheSmartMonkey/create-typescript-npm-library","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheSmartMonkey%2Fsimple-passwordless-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheSmartMonkey%2Fsimple-passwordless-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheSmartMonkey%2Fsimple-passwordless-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TheSmartMonkey%2Fsimple-passwordless-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TheSmartMonkey","download_url":"https://codeload.github.com/TheSmartMonkey/simple-passwordless-auth/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243667577,"owners_count":20328032,"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":"2025-01-21T16:29:19.324Z","updated_at":"2025-03-15T00:30:50.375Z","avatar_url":"https://github.com/TheSmartMonkey.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# simple-passwordless-auth\n\nA lightweight and simple library for passwordless authentication. Built to help you get things done quickly and securely\n\n![code-example](https://github.com/TheSmartMonkey/simple-passwordless-auth/blob/main/.github/images/code-example.png)\n\n## Installation\n\n```sh\nnpm i simple-passwordless-auth\n```\n\n## Features\n\n- [x] Google OAuth2\n- [x] Passwordless authentication with a Drizzle ORM integration (you can also use your own database / ORM)\n\n## Simple examples\n\n### Passwordless authentication\n\n```ts\nimport { login, validateCode } from 'simple-passwordless-auth';\n\n// Login with email\nlet authCode;\nawait login(\n  email,\n  (user) =\u003e {\n    console.log('getUserByEmailAndUpdateUserIfExist');\n    authCode = user.authCode;\n    console.log({ authCode });\n    return Promise.resolve({} as UserDao);\n  },\n  () =\u003e {\n    console.log('createUser');\n    return Promise.resolve();\n  },\n  () =\u003e {\n    console.log('sendEmailWithVerificationCode');\n    return Promise.resolve();\n  },\n);\n\n// Validate the auth code\nconst isValid = await validateCode(process.env.JWT_SECRET ?? '', email, authCode, () =\u003e {\n  console.log('getUserByEmail');\n  return Promise.resolve({} as UserDao);\n});\n```\n\n### Google OAuth2\n\n```ts\nimport { initGoogleOAuth2Client } from 'simple-passwordless-auth';\n\nconst googleClient = initGoogleOAuth2Client(\n  process.env.GOOGLE_CLIENT_ID,\n  process.env.GOOGLE_CLIENT_SECRET,\n  process.env.GOOGLE_REDIRECT_URL,\n);\n\n// Redirect user to googleAuthUrl\nconst googleAuthUrl = getGoogleAuthUrl(googleClient);\n\n// Handle the callback in a separate route\nconst userInfo = await handleGoogleCallback(googleClient, code);\n```\n\n#### Setup Google OAuth2\n\n1. Go to [Google Cloud Console](https://console.cloud.google.com/)\n2. Create a new project\n3. Enable the Google OAuth2 API\n4. Init a new OAuth consent screen\n5. Create credentials for OAuth2 client ID and secret (copy the client ID and secret to `initGoogleOAuth2Client()`)\n6. Set the redirect URL (example: `http://localhost:3000/auth/google/callback`)\n\n## Rich example\n\nSee [debug/main.ts](debug/main.ts) for a complete example\n\n### Contributing\n\nSee [CONTRIBUTING.md](CONTRIBUTING.md) for more information\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesmartmonkey%2Fsimple-passwordless-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthesmartmonkey%2Fsimple-passwordless-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthesmartmonkey%2Fsimple-passwordless-auth/lists"}