Job Search update — Rails and OAuth

gem 'jwt'
gem 'oath2'
match '/auth/:provider/callback', to: 'sessions#facebook', via: [:get, :post]
<%= link_to('Log in with Facebook!', '/auth/facebook') %>
class SessionsController < ApplicationController
...

def facebook
# finds existing user or creates new user based on omniAuth
# login
@user = User.find_or_create_by(uid: auth['uid']) do |u|
u.name = auth['info']['name']
u.email = auth['info']['email']
u.password = SecureRandom.hex
end

if @user.save
# if user is new, creates a new user entry in Users table,
# logs them in/starts new session
start_session
else
# if user already exists from previous omniauth login,
# logs them in/starts new session
start_session
end
end

...

private

...
def auth
request.env['omniauth.auth']
end

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store