aboutsummaryrefslogtreecommitdiff
path: root/src/actions/mixins/auth/require_sign_in.cr
blob: 27a6f5ea01a2293ffde6645a65513b7c8c82db65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module Auth::RequireSignIn
  macro included
    before require_sign_in
  end

  private def require_sign_in
    if current_user?
      continue
    else
      Authentic.remember_requested_path(self)
      flash.info = "Please sign in first"
      redirect to: SignIns::New
    end
  end

  # Tells the compiler that the current_user is not nil since we have checked
  # that the user is signed in
  private def current_user : User
    current_user?.as(User)
  end
end