Код: Выделить всё
val json = parseToJsonElement("""
{"name":"$name","password":"$password"}}"""
Раньше я мог войти в систему с помощью своего токена JSON через Android для devise, пока не решил добавить собственные представления.
Как исправить?
В консоли:
Код: Выделить всё
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)
Код: Выделить всё
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
Код: Выделить всё
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
Код: Выделить всё
Rails.application.config.middleware.insert_before 0, Rack::Cors do
allow do
origins "*"
resource "*",
headers: :any,
methods: [:get, :post, :put, :patch, :delete, :options, :head]
end
end
Подробнее здесь: https://stackoverflow.com/questions/793 ... json-token
Мобильная версия