Skip to content

Commit 255aad8

Browse files
authored
Fix sessions controller (#14)
* make color usage consistent * fix sessions controller * add sample requests with curl
1 parent efd082b commit 255aad8

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

README.md

+7
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ Request
3838

3939
```bash
4040
http --form POST 127.0.0.1:3000/api/v1/registration first_name='moses' last_name='gathuku' email='[email protected]' password='secret'
41+
42+
# curl -H "Content-Type: application/json" -d @register.json localhost:3000/api/v1/registration
4143
```
4244

4345
Registration Sucess
@@ -69,6 +71,11 @@ Registration Failure
6971

7072
__Sign In__
7173

74+
Request;
75+
```bash
76+
curl -H "Content-Type: application/json" -d @signin.json localhost:3000/api/v1/sessions
77+
```
78+
7279
Sign In Success - Returns a JWT token
7380

7481
```json

app/controllers/api/v1/sessions_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# frozen_string_literal: true
22

33
class Api::V1::SessionsController < ApplicationController
4-
before_action :authenticate_user, only: ['destroy']
4+
before_action :authenticate_user!, only: ['destroy']
55
def create
66
user = User.find_by_email(session_params[:email])
77
if user&.valid_password?(session_params[:password])

template.rb

+7-6
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
DEFAULT_DEVISE_AUTH_MODE = 'devise_jwt_strategy'
77
NO_QUESTIONS = ENV['INTERACTIVE'] == 'false'
8+
OUTPUT_COLOR = %i[blue bold].freeze
89

910
# Copied from: https://github.com/mattbrictson/rails-template
1011
# Add this template directory to source_paths so that Thor actions like
@@ -80,7 +81,7 @@ def devise_jwt_strategy
8081
"
8182
end
8283

83-
# implement device strategy
84+
# implement devise strategy
8485
content = <<-RUBY
8586
config.warden do |manager|
8687
#manager.intercept_401 = false
@@ -137,7 +138,7 @@ def respond
137138
end
138139
end
139140

140-
def device_simple_token_auth
141+
def devise_simple_token_auth
141142
# authenticable model
142143
insert_into_file 'app/models/user.rb', after: 'class User < ApplicationRecord' do
143144
"
@@ -158,10 +159,10 @@ def device_simple_token_auth
158159

159160
def auth_mode
160161
say
161-
if yes?('Use JWT instead of simple Token ?', :blue)
162+
if yes?('Use JWT instead of simple Token? [y/n]', OUTPUT_COLOR)
162163
devise_jwt_strategy
163164
else
164-
device_simple_token_auth
165+
devise_simple_token_auth
165166
end
166167
end
167168

@@ -204,7 +205,7 @@ def install_sidekiq
204205
end
205206

206207
say
207-
say 'Application generated successfully', %i[blue bold]
208+
say 'Application generated successfully', OUTPUT_COLOR
208209
say
209-
say "cd #{app_name} to switch to app", %i[blue bold]
210+
say "cd #{app_name} to switch to app", OUTPUT_COLOR
210211
end

0 commit comments

Comments
 (0)