admin管理员组

文章数量:1125076

I looked at the parameters in rails console only to find out it added users so I did like this

val json = parseToJsonElement("""
        {"name":"$name","password":"$password"}}"""

However, it's still rejects it as 401 Unauthorized access on the rails side

I used to be able to login with my JSON token through Android for devise until I decided to add custom views

How to fix?

In console: ``` Started POST "/users/sign_in" for 127.0.0.1 at 2025-01-10 22:40:28 +0200 ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC /application='LoginApi'/ Processing by Devise::SessionsController#create as HTML Completed 401 Unauthorized in 25ms (ActiveRecord: 0.0ms (0 queries, 0 cached) | GC: 0.0ms)

Processing by Devise::SessionsController#new as HTML Completed 200 OK in 16ms (Views: 0.2ms | ActiveRecord: 3.3ms (0 queries, 0 cached) | GC: 0.0ms)


Regestration controller: ``` # POST /resource
  def create
    super
    logger.debug "here it is."
    devise_api_token = current_devise_api_token
    if devise_api_token
        render json: { message: "You are logged in as #{devise_api_token.resource_owner_name}"}, status: :ok
    else
        render json: { message: "You are not logged in"}, status: :unauthorised
    end
  end

Application Controller: ```class ApplicationController < ActionController::API before_action :configure_permitted_parameters, if: :devise_controller?

protected

def configure_permitted_parameters devise_parameter_sanitizer.permit(:sign_up, keys: [:name]) end end```

cors.rb:

   allow do
     origins "*"

     resource "*",
       headers: :any,
       methods: [:get, :post, :put, :patch, :delete, :options, :head]
   end
 end

tried with and without config.authentication_keys = [:name] in config/devise.rb

本文标签: androidDevise not accepting JSON TokenStack Overflow