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
20 21 22 23 24 25 26 27 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 20 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
47 48 49 50 51 52 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 47 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
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 32 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'] ? response['data']['redirect_url'] : '/' else redirect_to '/' end end |
#mints_user_signed_in? ⇒ Boolean
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/mints/helpers/user_auth_helper.rb', line 3 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 |