1

I am sending the request to register a user from my Next.js frontend like this:

const res = await fetch("http://localhost:3000/create", {
    method: "POST",
    headers: {
      "Contet-Type": "application/json",
    },
    body: JSON.stringify({ user: {values}),
  });

  const data = await res.json();

where the values are username, email, pw, pw confirmation...the usual. Here are my headers from the request, which confirm that the payload is being sent as expected:

General:
Request URL: http://localhost:3000/create
Request Method: POST
Status Code: 204 No Content
Remote Address: 127.0.0.1:3000
Referrer Policy: strict-origin-when-cross-origin

Response headers:
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS, HEAD
Access-Control-Allow-Origin: http://localhost:3001
Access-Control-Max-Age: 1728000
Cache-Control: no-cache
Vary: Origin
X-Request-Id: a044ad4b-dbb3-41ed-80bd-ca933871b924
X-Runtime: 115.547357

Request headers:
Accept: */*
Accept-Encoding: gzip, deflate, br
Accept-Language: en,nl;q=0.9,hr;q=0.8,en-GB;q=0.7,en-US;q=0.6
Connection: keep-alive
Content-Length: 27
Content-Type: text/plain;charset=UTF-8
Contet-Type: application/json
Host: localhost:3000
Origin: http://localhost:3001
Referer: http://localhost:3001/
sec-ch-ua: "Chromium";v="92", " Not A;Brand";v="99", "Google Chrome";v="92"
sec-ch-ua-mobile: ?0
Sec-Fetch-Dest: empty
Sec-Fetch-Mode: cors
Sec-Fetch-Site: same-site
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/92.0.4515.131 Safari/537.36

Request payload:
{user:{email:"ggggg@gmail.com", username:"myusername", password:"123123",password_confirmation:"123123"}}

But what happens is the parameters from the frontend request never show up in my controllers.

So naturally, my first step was to byebug my rails controller in order to figure out what is going on, and when I do that all I see from params is:

<ActionController::Parameters {"controller"=>"user", "action"=>"create"} permitted: false>

My user params are nowhere to be seen. What is going on here?

I even started another rails project through a template: https://github.com/rchuasing/rails-api-boilerplate

and the same thing keeps happening again, I am recieving no parameters in any controller.

Here is my controller that I've stripped down to bare minimum in order to just test the params:

class UserController < ApplicationController
    def create
        # this is where I look for params
        byebug
    end

    def user_params
        params.require(:user).permit(:email, :username, :password, 
                                     :password_confirmation)
    end
end

Model:

class User < ApplicationRecord
  include Devise::JWT::RevocationStrategies::JTIMatcher
  devise :database_authenticatable, :registerable, :jwt_authenticatable, 
  jwt_revocation_strategy: self
end

I have tried everything I could think of, that includes making a new app and trying all kinds of various headers, but the params never get to the backend.

juliomalves
  • 42,130
  • 20
  • 150
  • 146
norther
  • 43
  • 5
  • did you configured [devise_parameter_sanitizer.permit](https://stackoverflow.com/questions/19791531/how-to-specify-devise-parameter-sanitizer-for-edit-action) – Chandan Aug 07 '21 at 18:58
  • The issue was with react/next. I user an older version of next, and with that version everything worked normally, so I think the problem was in Next. – norther Aug 08 '21 at 08:36

0 Answers0