Last active
August 25, 2019 14:28
-
-
Save rwehresmann/bc8a97e54fef76d97ceeecee062a7250 to your computer and use it in GitHub Desktop.
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 Auth0Controller < ApplicationController | |
| ... | |
| def callback | |
| user = find_or_create_user | |
| session[:user_id] = user.id | |
| if user.admin? | |
| session[:admin_user_id] = user.id | |
| redirect_to admin_root_path | |
| else | |
| redirect_to root_path | |
| end | |
| end | |
| private | |
| def find_or_create_user | |
| info = request.env.fetch('omniauth.auth').fetch('info') | |
| user_email = info.fetch('email') | |
| user = User.find_by(email: user_email) | |
| return user if user | |
| User.create!(email: user_email) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment