{"id":21089883,"url":"https://github.com/combine/objection-auth","last_synced_at":"2025-10-18T03:57:08.963Z","repository":{"id":57312898,"uuid":"123635944","full_name":"combine/objection-auth","owner":"combine","description":"Authentication methods for Objection.js","archived":false,"fork":false,"pushed_at":"2018-07-20T04:53:14.000Z","size":157,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-09-25T21:28:27.151Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","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/combine.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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":"2018-03-02T22:07:47.000Z","updated_at":"2020-03-27T18:11:59.000Z","dependencies_parsed_at":"2022-09-20T23:30:22.149Z","dependency_job_id":null,"html_url":"https://github.com/combine/objection-auth","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/combine%2Fobjection-auth","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/combine%2Fobjection-auth/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/combine%2Fobjection-auth/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/combine%2Fobjection-auth/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/combine","download_url":"https://codeload.github.com/combine/objection-auth/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225431440,"owners_count":17473362,"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":"2024-11-19T21:32:32.924Z","updated_at":"2025-10-18T03:57:03.898Z","avatar_url":"https://github.com/combine.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Build Status](https://travis-ci.org/combine/objection-auth.svg?branch=master)](https://travis-ci.org/combine/objection-auth)\n[![Coverage Status](https://coveralls.io/repos/github/combine/objection-auth/badge.svg?branch=master)](https://coveralls.io/github/combine/objection-auth?branch=master)\n\n# Authentication for Objection.js\n\nThis package includes plugins useful for authentication for websites:\n\n- **Authenticatable** - Generates hashed passwords for a user model. Uses `bcrypt` under the hood.\n- **Recoverable** - Generates password reset tokens.\n\n## Installation\n```\nnpm install objection-auth\n```\n\n## Usage\n\n### Authenticatable\n\n```js\n// Import the plugin.\nconst { Authenticatable } = require('objection-auth');\nconst { Model } = require('objection');\n\n// Mixin the plugin.\nconst AuthenticatableModel = Authenticatable({\n  passwordField: 'password',\n  saltRounds: 12,\n})(Model);\n\n// Create your model.\nclass User extends AuthenticatableModel {\n  // ...code\n}\n```\n\n#### Verifying a password\n\nIn your login controller logic:\n\n```js\nconst user = await User.query().where('id', 1);\n\nif (!user.verifyPassword) {\n  // throw an error\n}\n```\n\n#### Options\n#### `passwordField` (required)\nThe field to that the hashed password will be stored on. (required, defaults to 'password')\n\n#### `saltRounds` (defaults to `slug`)\nThe number of salt rounds as passed to `bcrypt`.\n\n### Recoverable\n\n```js\n// Import the plugin.\nconst { Recoverable } = require('objection-auth');\nconst { Model } = require('objection');\n\n// Mixin the plugin.\nconst RecoverableModel = Recoverable({\n  tokenField: 'resetPasswordToken',\n  tokenExpField: 'resetPasswordExp',\n  expiresIn: 60\n})(Model);\n\n// Create your model.\nclass User extends RecoverableModel {\n  // ...code\n}\n```\n\n#### Generating a reset token\n\nIn your reset password controller logic:\n\n```js\nconst user = await User.query().where('id', 1);\n\nawait user.generateResetToken();\nconsole.log(user.resetPasswordToken);\n//\n```\n\n#### Options\n#### `tokenField` (defaults to `resetPasswordToken`)\nThe field that the reset token is stored on.\n\n#### `tokenExpField` (defaults to `resetPasswordExp`)\nThe field that the expiration date is stored on.\n\n#### `expiresIn` (defaults to `60` minutes)\nThe expiration time of the token, in minutes.\n\n## Chaining Plugins\n\nThese plugins can be used together by composing the plugins together:\n\n```js\n\nconst { Authenticatable, Recoverable } = require('objection-auth');\nconst { compose, Model } = require('objection');\n\nconst mixins = compose(\n  Authenticatable({ saltRounds: 10, passwordField: 'pass' }),\n  Recoverable({\n    tokenField: 'resetPasswordToken',\n    tokenExpField: 'resetPasswordExp',\n    expiresIn: 60\n  })\n);\n\nclass User extends mixins(Model) {\n  // ...\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcombine%2Fobjection-auth","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcombine%2Fobjection-auth","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcombine%2Fobjection-auth/lists"}