Skip to content

Conversation

@Smokashi23
Copy link
Owner

No description provided.

class ApplicationController < ActionController::API
end
before_action :authorized

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Smokashi23 Please fix spacing and indentation

begin
JWT.decode(token, Rails.application.credentials[:secret_key_base] )
rescue JWT::DecodeError
nil

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Smokashi23 Do not return nil from this function, instead return some error message i.e. 'Unable to decode token'

def authorized
@user = User.find_by!(email: user_params[:email])
if current_user.nil?
render json: { message: 'Please log in' }, status: :unauthorized

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use I18n.t for displaying any message

token: @token
}, status: :accepted
else
render json: {message: 'Incorrect password'}, status: :unauthorized

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use I18 for displaying message

end

def handle_record_not_found(e)
render json: { message: "User doesn't exist" }, status: :unauthorized

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
render json: { message: "User doesn't exist" }, status: :unauthorized
render json: { message: I18n.t(''message') }, status: :unauthorized

end

end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary spacing

@@ -0,0 +1,15 @@
class User < ApplicationRecord
validates :email, presence: true, uniqueness: { message: " already exist" }, format: { with: /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i , message: "Invalid"}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message should be displayed through I18n only

require "test_helper"

class AuthsControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Smokashi23 Please do not commit unnecessary files

@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html

# This model initially had no columns defined. If you add columns to the

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not commit unnecessary files


class UsersControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary file

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants