{"id":13489414,"url":"https://github.com/zeusdeux/jwt-example","last_synced_at":"2025-03-17T17:31:15.180Z","repository":{"id":36293481,"uuid":"203261167","full_name":"zeusdeux/jwt-example","owner":"zeusdeux","description":"Playing with user registration, login/logout, auth, etc using JWTs, serverless functions \u0026 faunadb as the data store.","archived":false,"fork":false,"pushed_at":"2023-03-01T19:04:59.000Z","size":1330,"stargazers_count":22,"open_issues_count":8,"forks_count":4,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-28T02:22:57.089Z","etag":null,"topics":["faunadb","jwt","jwt-bearer-tokens","lambda","now","serverless","zeit"],"latest_commit_sha":null,"homepage":"https://jwt-example.zdx.cat","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/zeusdeux.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}},"created_at":"2019-08-19T22:49:33.000Z","updated_at":"2024-05-22T01:18:18.000Z","dependencies_parsed_at":"2024-01-16T09:19:07.114Z","dependency_job_id":null,"html_url":"https://github.com/zeusdeux/jwt-example","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fjwt-example","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fjwt-example/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fjwt-example/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zeusdeux%2Fjwt-example/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zeusdeux","download_url":"https://codeload.github.com/zeusdeux/jwt-example/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243872414,"owners_count":20361473,"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":["faunadb","jwt","jwt-bearer-tokens","lambda","now","serverless","zeit"],"created_at":"2024-07-31T19:00:26.880Z","updated_at":"2025-03-17T17:31:14.794Z","avatar_url":"https://github.com/zeusdeux.png","language":"TypeScript","readme":"# jwt-example\n\nThis is an example codebase that implements user registration and supports authorization using\n[JWTs](https://jwt.io) using serverless functions and the wonderful [FaunaDB](https://fauna.com).\n\n## Motivation\n\nI wrote this to teach myself how JWTs work and also implement user registration and login/logout,\netc flows serverlessly.\n\n## Implemented functionality\n\n- sign up as new user (or re-sign up as a deleted user which is transparent to the user)\n- login and get JWT with 1 hour expiry (multiple logged in sessions supported)\n- access protected route with only with a valid token\n- logout (kills _all_ logged in sessions and invalidates all tokens for the user)\n- delete user\n- In-situ encrypted JWT signing/validation key pair to overcome\n  [AWS Lambda having a hard limit of 4kb on env vars when JSON-stringified](https://github.com/zeusdeux/jwt-example/commit/4f09c2e56df2d95ac9df0082fad4bfc4e22fbddd#comments)\n\n## TODOs\n\n- todos in code\n- switch to `argon2` from `bcrypt`\n  \u003e Waiting on https://github.com/zeit/node-file-trace/pull/53 to switch to argon2\n\n## Code structure\n\n- `api/*` holds the lambdas that map to each supported route\n- `models/*` holds the models for the entities in the system (User \u0026 Token) and some helpers\n- `errors/*` holds the custom error tooling for the codebase\n- `utils/*` hold code structure and type level utilties\n\n### A note on `Maybe`, `Either` and `match` over traditional code structure\n\nI wanted to play with a different way of approaching authoring the code in this repository. Instead\nof messing with `try/catch`-es and lots of error handling madness, I have instead opted to push\nthose to the edges as you can see in [models/User.helpers.ts](./models/User.helpers.ts) and instead\nwrap those values in `Maybe`s and/or `Either`s. These values are then accessed in a declarative\nmanner using `match`. Their usage, imho, has greatly simplified the code as you can see in the\n`api/*.ts`. It's not everyone's ☕and I get that.\n\nMore info can be found in files with the same names under they `utils/` directory.\n","funding_links":[],"categories":["Open source example apps"],"sub_categories":["Other or no framework"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fjwt-example","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzeusdeux%2Fjwt-example","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzeusdeux%2Fjwt-example/lists"}