{"id":50718387,"url":"https://github.com/zaharsk/cookies-refresh-back","last_synced_at":"2026-06-09T21:03:07.754Z","repository":{"id":255539727,"uuid":"850797095","full_name":"zaharsk/cookies-refresh-back","owner":"zaharsk","description":"REST API to demonstrate the issue of RefreshToken and AccessToken cookies in NextJS 14. ","archived":false,"fork":false,"pushed_at":"2024-09-05T17:44:49.000Z","size":123,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-06-07T17:30:04.532Z","etag":null,"topics":["cookie","nestjs","nextjs","nextjs14","rest","rest-api"],"latest_commit_sha":null,"homepage":"https://cookies-refresh-back.koyeb.app","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/zaharsk.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-09-01T19:57:50.000Z","updated_at":"2024-09-05T17:45:28.000Z","dependencies_parsed_at":null,"dependency_job_id":"a9d0d3e0-cd13-4540-ab46-77413ec5b51c","html_url":"https://github.com/zaharsk/cookies-refresh-back","commit_stats":null,"previous_names":["zakharsk/cookies-refresh-back","zaharsk/cookies-refresh-back"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/zaharsk/cookies-refresh-back","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaharsk%2Fcookies-refresh-back","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaharsk%2Fcookies-refresh-back/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaharsk%2Fcookies-refresh-back/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaharsk%2Fcookies-refresh-back/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zaharsk","download_url":"https://codeload.github.com/zaharsk/cookies-refresh-back/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zaharsk%2Fcookies-refresh-back/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":34125332,"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":["cookie","nestjs","nextjs","nextjs14","rest","rest-api"],"created_at":"2026-06-09T21:03:06.342Z","updated_at":"2026-06-09T21:03:07.749Z","avatar_url":"https://github.com/zaharsk.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"## General\nThis application uses the standard [NestJS](https://nestjs.com/) template with [Prisma](https://www.prisma.io/) and [Passport](https://www.passportjs.org/).\n## Project setup\n```sh\nnpm install\n```\n```sh\nnpx prisma migrate deploy\n```\n## Compile and run the project\n```sh\nnpm run start:dev\n```\n## .env\nYou need to rename the `.env.example` file to `.env` and write any non-empty values for `ACCESS_JWT_SECRET` and `REFRESH_JWT_SECRET`.\nThe `ACCESS_JWT_EXPIRES_IN` and `REFRESH_JWT_EXPIRES_IN` values are used to set the lifetime of tokens, and to set the `Max-Age` parameter of the cookies being sent.\n## Endpoints\n- `/tokens`\n    - `GET /tokens`\n        - Get new tokens pair\n        - Require `Authorization` header with `Bearer {token}` value. See above.\n        - Returns nothing with `Set-Cookie` headers: `AccessToken` \u0026 `RefreshToken`\n    - `PATCH /tokens`\n        - Refresh tokens\n        - Require `Cookie` header with `RefreshToken={jwt}`\n        - Returns nothing with `Set-Cookie` headers: `AccessToken` \u0026 `RefreshToken`\n    - `DELETE /tokens`\n        - Delete hash of `RefreshToken` from the database\n        - Requires `Cookie` header with `AccessToken={jwt}`\n        - Returns nothing with `Set-Cookie` headers: empty `AccessToken` \u0026 `RefreshToken` with `Max-Age=0`\n- `/users`\n    - `GET /users`\n        - Get full list of users\n        - Require `Cookie` header with `AccessToken={jwt}`\n        - Returns array of objects with limited user data:\n          ```ts\n          [\n              {\n                  id: string,\n                  login: string,\n              },\n              { ... }\n          ]\n          ```\n    - `GET /users/{userId}`\n        - Get current user data\n        - Require `Cookie` header with `AccessToken={jwt}`\n        - Limited by current `userId`, extracted from `AccessToken`. You can't read data of another user.\n        - Returns object with full user data:\n          ```ts\n          {\n              id: string;\n              login: string;\n              passwordHash: string;\n              refreshTokenHash: string;\n              createdAt: string;\n              updatedAt: string;\n          }\n          ```\n    - `DELETE /users/{userId}`\n        - Delete current user\n        - Require `Cookie` header with `AccessToken={jwt}`\n        - Limited by current `userId`, extracted from `AccessToken`. You can't delete another user.\n        - Returns nothing\n## REST API clients\nIn the root folder of the project there is a `REST_API_Clients` folder with files for importing into popular REST API clients: [Insomnia](https://insomnia.rest/), [Bruno](https://www.usebruno.com/) and general [OpenAPI](https://www.openapis.org/) specification.\n## Authorization Bearer\nTo get Bearer token we need to take an object with authorization data:\n```ts\nconst loginData = {\n\tlogin: user-login,\n\tpassword: user-password\n}\n```\nProcess all fields using `encodeURIComponent`:\n```ts\nloginData.login = encodeURIComponent(loginData.login);  \nloginData.password = encodeURIComponent(loginData.password);\n```\nConvert an object to a string using `JSON.stringify`:\n```ts\nconst jsonString = JSON.stringify(loginData);\n```\nConvert the received string to BASE64 format:\n```ts\nconst b64String = btoa(jsonString);\n```\nThe result should be used as a Bearer token. \n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaharsk%2Fcookies-refresh-back","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzaharsk%2Fcookies-refresh-back","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzaharsk%2Fcookies-refresh-back/lists"}