You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm getting a strange error when trying to log in using CAS. When I first try to log in with CAS, I get redirected back to /users/sign_in. Looking at the logs, it seems like the user is signed in and redirected, but the current_user is not set properly.
I would like to either find and update a user if they already exist, or create a new user if not. This is what I see in the logs:
Started GET "/users/auth/cas/callback?...
Processing by OmniauthCallbacksController#cas as HTML
Redirected to http://example.com/dashboard
Processing by DashboardController#show as HTML
Completed 401 Unauthorized in 12ms (ActiveRecord: 0.9ms)
Started GET "/users/sign_in"...
However, if I click "Sign in with CAS" again, I am signed in and redirected as expected.
In DashboardController, I have before_action :authenticate_user!
And in my User model:
defself.from_omniauth(auth)ifUser.where(uid: auth.extra.uid).present?user=User.find_by(uid: auth.extra.uid)# Find a user if they were previously saved using email and passwordelsifUser.where(email: auth.extra.mail).present?user=User.find_by(email: auth.extra.mail)elseuser=User.newenduser.provider=auth.provideruser.uid=auth.extra.uiduser.display_name=auth.extra.cnuser.email=auth.extra.mailuser.password=Devise.friendly_token[0,20]user.save!userend
If I split up sign_in_and_redirect into seperate statements like so:
Which makes me think this is an issue with sessions and redirection rather than signing in. I tried deleting a user and re-adding them to see if the issue only happens with existing users, but the issue persists with newly-created users as well.
The text was updated successfully, but these errors were encountered:
I'm getting a strange error when trying to log in using CAS. When I first try to log in with CAS, I get redirected back to
/users/sign_in
. Looking at the logs, it seems like the user is signed in and redirected, but the current_user is not set properly.I would like to either find and update a user if they already exist, or create a new user if not. This is what I see in the logs:
However, if I click "Sign in with CAS" again, I am signed in and redirected as expected.
In my OmniauthCallbacksController, I have:
In DashboardController, I have
before_action :authenticate_user!
And in my User model:
If I split up
sign_in_and_redirect
into seperate statements like so:I get the same result but see this in the logs:
Which makes me think this is an issue with sessions and redirection rather than signing in. I tried deleting a user and re-adding them to see if the issue only happens with existing users, but the issue persists with newly-created users as well.
The text was updated successfully, but these errors were encountered: