- POST /users/signup
- POST /users/signin
- GET /users
Steps :
- Create new rails API app $ rails new latihan-auth --api -T --database=postgresql
- Modify gemfile
- gem 'bcrypt', '~> 3.1.7'
- gem 'knock'
- Gem ‘jwt’
- gem 'active_model_serializers'
- $ bundle install
- $ rails g model user username:string email:string password_digest:string
- $ rails g controller users
- $ rails g model article title:string body:text
- $ rails db:create
- $ rails db:migrate
- $ rails g knock:install
- $ rails generate knock:token_controller user
- User model ~> has_secure_password
- Application controller ~> include Knock::Authenticable
- Modify knock.rb ( config.token_secret_signature_key = -> { Rails.application.credentials.read } )
- Modify user_token_controller.rb (skip_before_action :verify_authenticity_token )
- Adding and setup secrets.yml , $ rails secret
- Start writing CRUD method on user controller
- Modifying routes
- Fire up rails server
- POST localhost:3000/users/signup
{ "user": { "username":"didi", "email":"didi@email.com", "password":"123456", "password_confirmation":"123456" } }
- POST localhost:3000/users/signin ,
{ "auth": { "email":"didi@email.com", "Password":"123456" } }
- Get users localhost:3000/users and Add jwt to header request