Last active
January 30, 2020 10:52
-
-
Save wajeeh-devsinc/ec6ee955a8d678e4bc3bea606d4fb148 to your computer and use it in GitHub Desktop.
Rails User Authentication with Devise and simple_token_authentication
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Api::V1::RegistrationsController < Devise::RegistrationsController | |
before_action :ensure_params_exist, only: :create | |
skip_before_filter :verify_authenticity_token, :only => :create | |
# sign up | |
def create | |
user = User.new user_params | |
if user.save | |
render json: { | |
messages: "Sign Up Successfully", | |
is_success: true, | |
data: {user: user} | |
}, status: :ok | |
else | |
render json: { | |
messages: "Sign Up Failded", | |
is_success: false, | |
data: {} | |
}, status: :unprocessable_entity | |
end | |
end | |
private | |
def user_params | |
params.require(:user).permit(:email, :password, :password_confirmation) | |
end | |
def ensure_params_exist | |
return if params[:user].present? | |
render json: { | |
messages: "Missing Params", | |
is_success: false, | |
data: {} | |
}, status: :bad_request | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment