Henry Augustianno

Joined

60 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in No route matches [GET] "/auth/facebook"

I only use this gem so far

 gem 'omniauth-facebook'
gem 'omniauth' 

Posted in No route matches [GET] "/auth/facebook"

Hi folks!

I am just starting to learn Rails, I want to make a simple OAuth Facebook login and display it after a successful login.
I always got No route matches [GET] "/auth/facebook" and can't find anything useful online.

here's a snippet of my codes:
routes.rb:

Rails.application.routes.draw do
  get '/hello', to: 'hello#world'
  root 'welcome#index'
  get '/auth/:provider/callback', to: 'sessions#create'
end
# app/controllers/sessions_controller.rb

class SessionsController < ApplicationController
  def create
    auth = request.env['omniauth.auth']
    session[:user_info] = {
      name: auth.info.name,
      email: auth.info.email,
      image: auth.info.image
    }
    redirect_to root_path
  end
end
<!-- app/views/welcome/index.html.erb -->

<h1>Hello, World!</h1>

<% if session[:user_info] %>
  <h2>Welcome <%= session[:user_info][:name] %>!</h2>
  <p>Email: <%= session[:user_info][:email] %></p>
  <img src="<%= session[:user_info][:image] %>" alt="Profile Image">
<% else %>
  <%= link_to "Sign in with Facebook", '/auth/facebook' %>
<% end %>
# config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, 'FACEBOOK_APP_ID', 'FACEBOOK_APP_SECRET'
end

thanks in advance!