when making a POST request, an extra key shows up in render.com logs where the BE API is deployed.

i am working on a project for my backend class. I built my backend using PostgresQL and Ruby on Rails for my API. I am having problems with my fetch request from my front end client to the API i deployed on render.com
export const signinLandlord = async (email, password) => {
return fetch(`${baseApiUrl}/api/v1/auth/landlord`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
password: password,
}),
}).then((data) => data.json());
};
export const signinLandlord = async (email, password) => {
return fetch(`${baseApiUrl}/api/v1/auth/landlord`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
email: email,
password: password,
}),
}).then((data) => data.json());
};
I send a fetch request to the api with only the email and password in the body. In the console, it returns unauthorized EVEN IF the email and password is correct. i checked the logs on render.com where the API is deployed and it gives me this error:
May 27 02:34:19 PM I, [2023-05-27T06:34:19.493672 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Started POST "/api/v1/auth/landlord" for 162.158.178.187 at 2023-05-27 06:34:19 +0000
May 27 02:34:19 PM I, [2023-05-27T06:34:19.494462 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Processing by Api::V1::AuthenticationController#landlord_create as */*
May 27 02:34:19 PM I, [2023-05-27T06:34:19.494541 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "authentication"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}
May 27 02:34:19 PM I, [2023-05-27T06:34:19.511693 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Completed 401 Unauthorized in 17ms (Views: 0.3ms | ActiveRecord: 8.0ms | Allocations: 4790)
May 27 02:34:19 PM I, [2023-05-27T06:34:19.493672 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Started POST "/api/v1/auth/landlord" for 162.158.178.187 at 2023-05-27 06:34:19 +0000
May 27 02:34:19 PM I, [2023-05-27T06:34:19.494462 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Processing by Api::V1::AuthenticationController#landlord_create as */*
May 27 02:34:19 PM I, [2023-05-27T06:34:19.494541 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Parameters: {"email"=>"[email protected]", "password"=>"[FILTERED]", "authentication"=>{"email"=>"[email protected]", "password"=>"[FILTERED]"}}
May 27 02:34:19 PM I, [2023-05-27T06:34:19.511693 #73] INFO -- : [219e46fc-cc58-4495-9e89-d14a31281b3b] Completed 401 Unauthorized in 17ms (Views: 0.3ms | ActiveRecord: 8.0ms | Allocations: 4790)
1 Reply
Last
LastOP2y ago
it produces an extra "authentication" key and i don't know where that is coming from. in my rails controller, i only permitted email and password, without a top level key
class Api::V1::AuthenticationController < ApplicationController
skip_before_action :authenticate_request,
only: %i[landlord_create renter_create]

def landlord_create
# signin
@landlord, @error_messages = Landlord.signin(signin_params)

if @error_messages.nil?
serialized_token = TokenSerializer.serialize_user(@landlord)
render json: { landlord: serialized_token }, status: :ok
else
render json: { errors: @error_messages }, status: :unauthorized
end
end


private

def signin_params
params.permit(:email, :password)
end
end
class Api::V1::AuthenticationController < ApplicationController
skip_before_action :authenticate_request,
only: %i[landlord_create renter_create]

def landlord_create
# signin
@landlord, @error_messages = Landlord.signin(signin_params)

if @error_messages.nil?
serialized_token = TokenSerializer.serialize_user(@landlord)
render json: { landlord: serialized_token }, status: :ok
else
render json: { errors: @error_messages }, status: :unauthorized
end
end


private

def signin_params
params.permit(:email, :password)
end
end
these are my routes
scope '/auth' do
post '/landlord', to: 'authentication#landlord_create'
post '/renter', to: 'authentication#renter_create'
end
scope '/auth' do
post '/landlord', to: 'authentication#landlord_create'
post '/renter', to: 'authentication#renter_create'
end
im lost really and i dont know what do do and how to debug this
Want results from more Discord servers?
Add your server