Преглед на файлове

Provide means to login/logout in user auth concern

Andrew Swistak преди 5 години
родител
ревизия
8dbe448c80
променени са 1 файла, в които са добавени 12 реда и са изтрити 0 реда
  1. 12 0
      app/controllers/concerns/user_authentication.rb

+ 12 - 0
app/controllers/concerns/user_authentication.rb

@@ -7,6 +7,8 @@ module UserAuthentication
 
   included do
     def current_user
+      return unless jwt
+
       @current_user ||=
         begin
           result = JsonWebToken.decode(jwt)
@@ -25,6 +27,16 @@ module UserAuthentication
     def logged_in?
       !current_user.nil?
     end
+
+    def login(user)
+      self.current_user = user
+    end
+
+    def logout
+      cookies.delete(:jwt)
+      cookies.delete(:_csrf_token)
+      cookies.delete('x-csrf-token')
+    end
   end
 
   private