Skip to content

Instantly share code, notes, and snippets.

@truongnmt
Created January 9, 2022 22:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save truongnmt/7d3f9e02a522302417a4c3ab98b2b36f to your computer and use it in GitHub Desktop.
Save truongnmt/7d3f9e02a522302417a4c3ab98b2b36f to your computer and use it in GitHub Desktop.
sessions_controller.rb
class SessionsController < ApplicationController
def create
user = User.find_by(username: session_params[:username])
if user
get_options = WebAuthn::Credential.options_for_get(allow: user.credentials.pluck(:external_id))
session[:current_authentication] = { challenge: get_options.challenge, username: session_params[:username] }
respond_to do |format|
format.json { render json: get_options }
end
else
respond_to do |format|
format.json { render json: { errors: ["Username doesn't exist"] }, 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