{"id":19857748,"url":"https://github.com/aloiscrr/ts-api-users","last_synced_at":"2026-06-09T08:32:39.083Z","repository":{"id":42649323,"uuid":"249766568","full_name":"AloisCRR/ts-api-users","owner":"AloisCRR","description":"REST API powered by TypeScript, JsonWebToken for auth and more.","archived":false,"fork":false,"pushed_at":"2022-12-22T20:52:52.000Z","size":235,"stargazers_count":1,"open_issues_count":10,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-28T23:47:13.160Z","etag":null,"topics":["authentication","jsonwebtoken","rest-api","typescript"],"latest_commit_sha":null,"homepage":"","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/AloisCRR.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":"2020-03-24T16:58:09.000Z","updated_at":"2023-03-07T07:05:57.000Z","dependencies_parsed_at":"2023-01-30T17:01:06.888Z","dependency_job_id":null,"html_url":"https://github.com/AloisCRR/ts-api-users","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/AloisCRR/ts-api-users","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AloisCRR%2Fts-api-users","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AloisCRR%2Fts-api-users/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AloisCRR%2Fts-api-users/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AloisCRR%2Fts-api-users/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AloisCRR","download_url":"https://codeload.github.com/AloisCRR/ts-api-users/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AloisCRR%2Fts-api-users/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34098932,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-06-09T02:00:06.510Z","response_time":63,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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","jsonwebtoken","rest-api","typescript"],"created_at":"2024-11-12T14:19:38.889Z","updated_at":"2026-06-09T08:32:39.064Z","avatar_url":"https://github.com/AloisCRR.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# TypeScript API with authentication\n\nThis project purpose is to learn about JWT auth flow, using TypeScript.\n\n## Run Locally\n\n1. Install both:\n\n   - [Node.js](https://nodejs.org/es/download/)\n   - [MongoDB](https://www.mongodb.com/try/download/community)\n\n   You will need to have MongoDB running on port 27017.\n\n2. Clone the project:\n\n   ```bash\n   git clone https://github.com/AloisCRR/ts-api-users.git\n   ```\n\n3. Go to the project directory:\n\n   ```bash\n   cd ts-api-users\n   ```\n\n4. Install dependencies:\n\n   ```bash\n   npm install\n   ```\n\n5. Start the dev server:\n\n   ```bash\n   npm run dev\n   ```\n\n   REST API will run in [http://localhost:3000](http://localhost:3000).\n\n6. To compile TypeScript to JavaScript and run the project:\n\n   ```bash\n   npm run build \u0026\u0026 npm start\n   ```\n\n## API Reference\n\n#### Sign up or register\n\n```http\nPOST /signup\n```\n\n| Body       | Type     | Description                      |\n| :--------- | :------- | :------------------------------- |\n| `email`    | `string` | **Required**. User email address |\n| `password` | `string` | **Required**. Account password   |\n\n#### Sign in or login\n\n```http\nPOST /signin\n```\n\n| Body       | Type     | Description                      |\n| :--------- | :------- | :------------------------------- |\n| `email`    | `string` | **Required**. User email address |\n| `password` | `string` | **Required**. Account password   |\n\n```http\nGET /auth\n```\n\n| Headers          | Type  | Description                                   |\n| :--------------- | :---- | :-------------------------------------------- |\n| `Authentication` | `JWT` | **Required**. Jwt given on sign in or sign up |\n\n## Screenshots\n\nBasic input validation\n\n![Screenshot](https://i.imgur.com/JQD2vth.png)\n\nInvalid password or email\n\n![Screenshot](https://i.imgur.com/B8Mzqk5.png)\n\nSuccessful sign in\n\n![Screenshot](https://i.imgur.com/hJoFb4B.png)\n\nSending token on headers\n\n![Screenshot](https://i.imgur.com/5r0cAo0.png)\n\nAuthorization\n\n![Screenshot](https://i.imgur.com/jcTFWIB.png)\n\n## Tech Stack\n\n| Name                                                       | Description                                                 |\n| ---------------------------------------------------------- | ----------------------------------------------------------- |\n| [Node.js](https://nodejs.org/es/download/)                 | Business logic                                              |\n| [MongoDB](https://www.mongodb.com/try/download/community)  | Database                                                    |\n| [Express](https://expressjs.com/es/api.html)               | HTTP Server                                                 |\n| [TypeScript](https://www.typescriptlang.org/)              | JavaScript super-set to add static code analysis            |\n| [JWT](https://jwt.io/)                                     | Library to generate JWTs                                    |\n| [Mongoose](https://mongoosejs.com/docs/api.html)           | ODM (Object Data Modeling)                                  |\n| [Passport JWT](https://www.npmjs.com/package/passport-jwt) | Passport strategy for authenticating with a JSON Web Token. |\n| [Bcrypt](https://www.npmjs.com/package/passport-jwt)       | Algorithm used to hash passwords.                           |\n\n## Lessons Learned\n\n### Route creation\n\n```typescript\nimport { Router } from \"express\";\nimport { signIn, signUp } from \"../controllers/user.controller\";\n\nconst router = Router();\n\nrouter.post(\"/signup\", signUp);\nrouter.post(\"/signin\", signIn);\n\nexport default router;\n```\n\n### Route controller\n\n```typescript\nrouter.get(\n  \"/auth\",\n  passport.authenticate(\"jwt\", { session: false }),\n  (req, res) =\u003e {\n    res.status(200).json({ msg: \"Auth route succeeded\" });\n  }\n);\n```\n\n### Create token\n\n```typescript\nfunction createToken(user: Iuser) {\n  return jwt.sign({ id: user.id, email: user.email }, config.jwtSecret, {\n    expiresIn: 86400,\n  });\n}\n```\n\nWorks in this way... With JWT obviously you can generate a token for authentication, a token can hold public data in a stateless way. Public info is like the algorithm used to sign token or the type of token, also included something called \"payload\" which is content or body of token (this includes all data registered for token).\n\nTo generate a token we use a function from jwt module called sign, passing a \"payload\" that is information that token will save, and a secret used to sign the token.\n\nToken is signed by a private key, and with the same key we can check if token is valid and use it to authenticate an user, passport takes his time in this, with passport-jwt we can use a function called passport.authenticate() which is a middleware that handles all the logic from getting the token from auth header to validate it and attach the token payload to the request object of express.\n\n## Roadmap\n\n- [x] App functionality\n- [ ] Testing\n- [ ] Hosting, domain, etc.\n- [ ] CI/CD\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloiscrr%2Fts-api-users","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faloiscrr%2Fts-api-users","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faloiscrr%2Fts-api-users/lists"}