Skip to content

Commit ce38e24

Browse files
Update README.md
1 parent e22d82f commit ce38e24

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

README.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Tokenable
22

3-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/tokenable`. To experiment with that code, run `bin/console` for an interactive prompt.
3+
Tokenable is a gem for Rails to enable the ability for API applications to provide Authentication.
44

5-
TODO: Delete this and the text above, and describe your gem
5+
This allows you to provide authentication to mobile apps, or SPAs with ease.
66

77
## Installation
88

@@ -14,21 +14,19 @@ gem 'tokenable'
1414

1515
And then execute:
1616

17-
bundle install
18-
19-
Or install it yourself as:
20-
21-
gem install tokenable
17+
```
18+
bundle install
19+
```
2220

2321
## Usage
2422

25-
In your `routes.rb`, please add:
23+
In your `config/routes.rb`, please add:
2624

2725
```ruby
2826
mount Tokenable::Engine => '/api/auth'
2927
```
3028

31-
And in your `User` model, please add an Auth strategy, such as:
29+
And in your `User` model, please add an Auth Strategy. For example, if you are using `has_secure_password`, then you could use:
3230

3331
```ruby
3432
class User < ApplicationRecord
@@ -43,7 +41,17 @@ You can chose from:
4341
- `Tokenable::Strategies::SecurePassword`
4442
- `Tokenable::Strategies::Devise`
4543

46-
You can also create your own stragery. (TODO: link to docs on this)
44+
You can also create your own stragery. This is as simple as creating a method on the User object.
45+
46+
```ruby
47+
def self.from_params(params)
48+
user = User.find_by(something: params[:something])
49+
return nil unless user.present?
50+
51+
return nil unless user.password_valid?(params[:password])
52+
user
53+
end
54+
```
4755

4856
Once you have this setup, you can login. For example, you could login using `axios` in JavaScript:
4957

0 commit comments

Comments
 (0)