Skip to content

Instantly share code, notes, and snippets.

@truongnmt
Created January 9, 2022 08:08
Show Gist options
  • Save truongnmt/6191c74af917ae354a770ab0bf4993c6 to your computer and use it in GitHub Desktop.
Save truongnmt/6191c74af917ae354a770ab0bf4993c6 to your computer and use it in GitHub Desktop.
registrations_controller.rb
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