/latihan-auth

This is Simple Rails API server using knock for mentoring in Binar Academy Backend Beginner Class

Primary LanguageRubyMIT LicenseMIT

README

Endpoints:

  1. POST /users/signup
  2. POST /users/signin
  3. GET /users

Homework : please complete the App..

Steps :

  1. Create new rails API app $ rails new latihan-auth --api -T --database=postgresql
  2. Modify gemfile
  • gem 'bcrypt', '~> 3.1.7'
  • gem 'knock'
  • Gem ‘jwt’
  • gem 'active_model_serializers'
  1. $ bundle install
  2. $ rails g model user username:string email:string password_digest:string
  3. $ rails g controller users
  4. $ rails g model article title:string body:text
  5. $ rails db:create
  6. $ rails db:migrate
  7. $ rails g knock:install
  8. $ rails generate knock:token_controller user
  9. User model ~> has_secure_password
  10. Application controller ~> include Knock::Authenticable
  11. Modify knock.rb ( config.token_secret_signature_key = -> { Rails.application.credentials.read } )
  12. Modify user_token_controller.rb (skip_before_action :verify_authenticity_token )
  13. Adding and setup secrets.yml , $ rails secret
  14. Start writing CRUD method on user controller
  15. Modifying routes
  16. Fire up rails server
  17. POST localhost:3000/users/signup

{ "user": { "username":"didi", "email":"didi@email.com", "password":"123456", "password_confirmation":"123456" } }

  1. POST localhost:3000/users/signin ,

{ "auth": { "email":"didi@email.com", "Password":"123456" } }

  1. Get users localhost:3000/users and Add jwt to header request