-
Notifications
You must be signed in to change notification settings - Fork 0
Feature1 #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Feature1 #1
Conversation
| class ApplicationController < ActionController::API | ||
| end | ||
| before_action :authorized | ||
|
|
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| render json: { message: "User doesn't exist" }, status: :unauthorized | |
| render json: { message: I18n.t(''message') }, status: :unauthorized |
| end | ||
|
|
||
| end | ||
|
|
There was a problem hiding this comment.
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"} | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 | |||
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unnecessary file
No description provided.