Created
January 9, 2022 08:08
-
-
Save truongnmt/6191c74af917ae354a770ab0bf4993c6 to your computer and use it in GitHub Desktop.
registrations_controller.rb
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 RegistrationsController < ApplicationController | |
def create | |
user = User.new(username: params[:registration][:username]) | |
create_options = WebAuthn::Credential.options_for_create( | |
user: { | |
name: params[:registration][:username], | |
id: user.webauthn_id | |
} | |
) | |
if user.valid? | |
session[:current_registration] = { challenge: create_options.challenge, user_attributes: user.attributes } | |
respond_to do |format| | |
format.json { render json: create_options } | |
end | |
else | |
respond_to do |format| | |
format.json { render json: { errors: user.errors.full_messages }, status: :unprocessable_entity } | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment