Created
January 9, 2022 22:25
-
-
Save truongnmt/7d3f9e02a522302417a4c3ab98b2b36f to your computer and use it in GitHub Desktop.
sessions_controller.rb
This file contains hidden or 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 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