README.md in researchable_jwt-authenticable-1.0.0 vs README.md in researchable_jwt-authenticable-1.0.1

- old
+ new

@@ -1,30 +1,52 @@ # JwtAuthenticable -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/jwt_authenticable`. To experiment with that code, run `bin/console` for an interactive prompt. +Researchable's JWT Authenticable gem. This gem provides a standard way of authenticating users using JWT tokens. -TODO: Delete this and the text above, and describe your gem - ## Installation Add this line to your application's Gemfile: ```ruby -gem 'jwt_authenticable' +gem 'researchable_jwt-authenticable' ``` And then execute: $ bundle install Or install it yourself as: - $ gem install jwt_authenticable + $ gem researchable_jwt-authenticable ## Usage -TODO: Write usage instructions here +Simply add the following to your `ApplicationController`: +```ruby +class ApplicationController < ActionController::API + include JwtAuthenticable::Auth + + before_action :authenticate_user! + before_action :set_profile! + + attr_accessor :current_profile + + # rest of your controller + + private + + # @note authorization_token! will raise an error if the token is invalid, but this is called after + # authenticate_user! which will raise the same error. Therefore we don't need to rescue the error here. + def set_profile! + uuid = authorization_token!['sub'] + @current_profile = Profile.find_by uuid: uuid + # If current_profile is nil, it is the first time the user is talking to base-backend. If the token is valid we + # can simply create a new profile. + @current_profile ||= Profile.create uuid: uuid + end +end +``` ## Development After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).