我正在使用Rails作为后端
devise-jwt
对前端部分做出反应。
我在跟踪这个
https://github.com/waiting-for-dev/devise-jwt/blob/master/README.md
my routes.rb文件包含:
Rails.application.routes.draw do
# remove this in production
require 'sidekiq/web'
mount Sidekiq::Web => '/sidekiq'
namespace :api, defaults: { format: 'json' } do
namespace :v1 do
devise_for :users, :controllers => {sessions: 'api/v1/sessions', registrations: 'api/v1/registrations'}
end
end
end
我的注册_controller.rb(app/controllers/api/registrations _controller.rb)
class Api::V1::RegistrationsController < Devise::RegistrationsController
respond_to :json, :controllers => {sessions: 'sessions', registrations: 'registrations'}
before_action :sign_up_params, if: :devise_controller?, on: [:create]
def create
build_resource(sign_up_params)
if resource.save
render :json => resource, serializer: Api::V1::UserSerializer, meta: { message: 'Sign up success', token: request.headers["Authorization"] }, :status => :created
else
render :json => resource, adapter: :json_api, serializer: ActiveModel::Serializer::ErrorSerializer, meta: { message: 'Sign up success' }, :status => :created
end
end
protected
def sign_up_params
params.require(:sign_up).permit(:first_name, :last_name, :mobile, :email, :password, :password_confirmation)
end
end
my sessions_controller.rb(app/controllers/api/sessions_controller.rb)
class Api::SessionsController < Devise::SessionsController
respond_to :json
end
我的应用程序_controller.rb(app/controllers/application_controller.rb)
class ApplicationController < ActionController::Base
end
基本上,下一步要做什么才能获得代币。我很困惑。我将如何获得aces令牌并使用它在前端react部分进行身份验证。