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
版权声明:本文标题:android - Devise not accepting JSON Token - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736652930a1946183.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论