Module: UserAuthHelper
- Included in:
- Mints::AdminBaseController, Mints::BaseApiController
- Defined in:
- lib/mints/helpers/user_auth_helper.rb
Instance Method Summary collapse
-
#mints_user_login(email, password) ⇒ Object
Mints user Login.
-
#mints_user_logout ⇒ Object
Mints user Logout.
-
#mints_user_magic_link_login(hash) ⇒ Object
Mints user Login.
- #mints_user_signed_in? ⇒ Boolean
Instance Method Details
#mints_user_login(email, password) ⇒ Object
Mints user Login.
Starts a user session in mints.cloud and set a session cookie
22 23 24 25 26 27 28 29 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 22 def mints_user_login(email, password) # Login in mints response = @mints_user.login(email, password) # Get session token from response session_token = response['api_token'] # Set a permanent cookie with the session token [:mints_user_session_token] = { value: session_token, secure: true, httponly: true, expires: 1.day } end |
#mints_user_logout ⇒ Object
Mints user Logout.
Destroy session from mints.cloud and delete local session cookie
49 50 51 52 53 54 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 49 def mints_user_logout # Logout from mints # @mints_user.logout # Delete local cookie .delete(:mints_user_session_token) end |
#mints_user_magic_link_login(hash) ⇒ Object
Mints user Login.
Starts a user session in mints.cloud and set a session cookie
34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 34 def mints_user_magic_link_login(hash) # Login in mints response = @mints_user.magic_link_login(hash) if response['data'] # Set a cookie with the session token [:mints_user_session_token] = { value: response['data']['api_token'], secure: true, httponly: true, expires: 1.day } redirect_to response['data']['redirect_url'] || '/' else redirect_to '/' end end |
#mints_user_signed_in? ⇒ Boolean
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 5 def mints_user_signed_in? begin # Check status in mints response = @mints_user.me['data'] rescue => e # Handle the client Unauthorized error # if mints response is negative delete the session cookie .delete(:mints_user_session_token) response = nil end response end |