Skip to content

Instantly share code, notes, and snippets.

@mayesa
Created June 13, 2019 14:36
Show Gist options
  • Save mayesa/d2737325c97a71ba44260d05de343f6e to your computer and use it in GitHub Desktop.
Save mayesa/d2737325c97a71ba44260d05de343f6e to your computer and use it in GitHub Desktop.
Rodauth GraphQL
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