Last active
December 21, 2018 15:59
-
-
Save robacarp/ef45825ba665f4f8b46cd78a82dce670 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
module Auth::RedirectIfSignedIn | |
macro included | |
include Auth::SkipRequireSignIn | |
before redirect_if_signed_in | |
# Most notably, this is removed everywhere. All actions now depend on a current_user. | |
# unexpose current_user | |
end | |
# ... | |
def current_user | |
end | |
end |
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
module SessionManagement | |
@user : User? | |
# ... | |
def current_user? | |
@user ||= begin | |
# #get? instead of #get | |
if id = session.get? SESSION_KEY | |
UserQuery.find id | |
end | |
end | |
end | |
end |
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
abstract class GuestLayout < Layout | |
# nothing in this file except the 'needs' | |
needs current_user : User? | |
end |
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
abstract class Layout | |
# ... | |
def login_button | |
li class: "nav-item" do | |
# @current_user will be a User? when using GuestLayout, and a User when using MainLayout | |
if @current_user | |
link "Log Out", to: Session::Delete, class: "nav-link" | |
else | |
link "Log In", to: Session::New, class: "nav-link" | |
end | |
end | |
end | |
end |
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
abstract class MainLayout < Layout | |
# nothing in this file except the 'needs' | |
needs current_user : User | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment