Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
Refer the wiki instead of including everything in the README
  • Loading branch information
mzrnsh authored Dec 13, 2023
1 parent 63b63e1 commit 0e73d47
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,43 +25,21 @@ See [Upgrading to Passwordless 1.0](docs/upgrading_to_1_0.md) for more details.

## Usage

Passwordless creates a single model called `Passwordless::Session`. It doesn't come with its own `User` model, it expects you to create one:
Passwordless creates a single model called `Passwordless::Session`, so it doesn't come with its own user model. Instead, it expects you to provide one, with an email field in place. If you don't yet have a user model, check out the wiki on [creating the user model](https://github.com/mikker/passwordless/wiki/Creating-the-user-model).

```sh
$ bin/rails generate model User email
```

Then specify which field on your `User` record is the email field with:
Enable Passwordless on your user model by pointing it to the email field:

```ruby
class User < ApplicationRecord
validates :email,
presence: true,
uniqueness: { case_sensitive: false },
format: { with: URI::MailTo::EMAIL_REGEXP }

passwordless_with :email # <-- here!
end
```

You might want to update the generated migration file to include db-level constraints similar to the model validation above:

```ruby
class CreateUsers < ActiveRecord::Migration[7.0]
def change
create_table :users do |t|
t.string :email, null: false

t.index 'LOWER(email)', unique: true, name: 'index_users_on_lowercase_email'

t.timestamps
end
end
# your other code..

passwordless_with :email # <-- here! this needs to be a column in `users` table

# more of your code..
end
```


Finally, mount the engine in your routes:
Then mount the engine in your routes:

```ruby
Rails.application.routes.draw do
Expand Down

0 comments on commit 0e73d47

Please sign in to comment.