Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to accept invitations anymore (but works via console) #598

Closed
thedanielmay opened this issue Oct 15, 2015 · 2 comments
Closed

Unable to accept invitations anymore (but works via console) #598

thedanielmay opened this issue Oct 15, 2015 · 2 comments

Comments

@thedanielmay
Copy link

As per: http://stackoverflow.com/questions/33144068/devise-invitable-not-able-to-accept-invitations-anymore-but-works-via-console

Thanks for a useful gem :) ... so:

I am using devise_invitable to create guest accounts to access a document. When accessing a document, a guest can click on an upgrade button that will upgrade to a full account. Clicking on the upgrade button is accepting devise_invitable invitation.

Was previously working: no longer working.

Environment:

  • rails 4.2.3 (recently upgraded)
  • devise 3.4.1
  • devise_invitable 1.3.6

I use a header partial for a guest user that generates an upgrade link:

<% @invite_link = accept_user_invitation_url(invitation_token: @invite_token) %>
<%= link_to "Upgrade", @invite_link, class: "btn btn-danger btn-lg" %>

@invite_token is created like:

user = current_user
user.invite! do |u|
  u.skip_invitation = true
end
@invite_token = user.raw_invitation_token

So link_to helper generates something like: https://myapp/users/invitation/accept?invitation_token=vv_JqeFDLfyX65tx2KhR

Except when I click on the link, it takes me to: https://myapp/users/sign_in

With error message: The invitation token provided is not valid!

Log reports something like:

Started GET "/users/invitation/accept?invitation_token=vv_JqeFDLfyX65tx2KhR" for 31.15.32.222 at 2015-10-15 19:18:34 +1100
Processing by Devise::InvitationsController#edit as HTML
  Parameters: {"invitation_token"=>"vv_JqeFDLfyX65tx2KhR"}
  User Load (5.9ms)  SELECT  "users".* FROM "users" WHERE "users"."invitation_token" = $1  ORDER BY "users"."id" ASC LIMIT 1  [["invitation_token", "ea9be9890c684e13ece13ec02f89bade81fcd3ac1fb982db72d8f8561d0cf289"]]
Redirected to https://myapp/
Filter chain halted as :resource_from_invitation_token rendered or redirected
Completed 302 Found in 53ms (ActiveRecord: 5.9ms)
Started GET "/" for 31.15.32.222 at 2015-10-15 19:49:52 +1100
Processing by PagesController#index as HTML
Redirected to https://myapp/users/sign_in
Completed 302 Found in 11ms (ActiveRecord: 0.0ms)

Am able to make this work via rails console.

If I run rails console in parallel, I am able to step through the above steps and generate an accept_invitation link that works as expected (i.e. it prompts user to set a password for the full account).

NB: the raw_invitation_token is different in the rails console session.

What am I missing?

@thedanielmay thedanielmay changed the title devise_invitable not able to accept invitations anymore (but works via console) Not able to accept invitations anymore (but works via console) Oct 15, 2015
@thedanielmay thedanielmay changed the title Not able to accept invitations anymore (but works via console) Unable to accept invitations anymore (but works via console) Oct 15, 2015
@scambra
Copy link
Owner

scambra commented Oct 15, 2015

raw invitation token is not saved in DB, so it's not possible to display in partial if token is not generated at the time of partial display, so you would need to generate a new token on every partial display. It's related to #589

@thedanielmay
Copy link
Author

@scambra Thanks very much for your response. The token here is generated at time of partial display, so not the problem this time :) but ...

I found code that called user.invite! to generate raw_invitation_token when page was displayed and after the accept_invitation link was generated. This meant that the token in the accept_invitation link was now outdated.

Going via the console, this code was not called as no controller, view or javascript components are invoked.

So it's all back to normal now. Much thanks for an awesome gem!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants