Created
June 13, 2019 14:36
-
-
Save mayesa/d2737325c97a71ba44260d05de343f6e to your computer and use it in GitHub Desktop.
Rodauth GraphQL
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
def handle_api_auth_operation(route) | |
operation_name = request.params["operationName"] | |
return if operation_name.blank? | |
# Set POST as default http_method | |
http_method = "POST" | |
path = '' | |
case operation_name | |
when 'Authenticate' | |
path = '/login' | |
when 'ForgotPassword' | |
http_method = "GET" | |
path = '/reset' | |
end | |
return if path.blank? | |
route.env["REQUEST_METHOD"] = http_method | |
route.instance_variable_set(:@remaining_path, path) | |
end | |
route do |r| | |
r.on('graphql') do | |
# Forward to rodauth REST endpoints if needed | |
handle_api_auth_operation(r) | |
# Init rodauth | |
r.rodauth | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment