Pow: "The invitation doesn't exist" when creating an invitation

Created on 12 Jun 2020  路  6Comments  路  Source: danschultzer/pow

Pow 1.0.20
Elixir 1.10.3
Phoenix 1.5.3

I have set up the PowInvitation extension as described in the documentation. I can navigate to /invitations/new and enter a username (I am using usernames instead of emails) and hit the submit button, however it redirects me to my index page with the error flash "The invitation does not exist".

Full Phoenix log for inviting a new user with the username "joe"

[info] GET /invitations/new
[debug] Processing with PowInvitation.Phoenix.InvitationController.new/2
  Parameters: %{}
  Pipelines: [:browser]
[info] Sent 200 in 5ms
[info] POST /invitations
[debug] Processing with PowInvitation.Phoenix.InvitationController.create/2
  Parameters: %{"_csrf_token" => "IBR6Y2MsChcDCSUxBT4aNCcaBxYLLVw6PR4PZEPN59mzjqmgKxeqzLjU", "user" => %{"username" => "joe"}}
  Pipelines: [:browser]
[debug] QUERY OK db=9.6ms queue=0.5ms idle=1052.7ms
INSERT INTO "users" ("invitation_token","invited_by_id","username","inserted_at","updated_at") VALUES ($1,$2,$3,$4,$5) RETURNING "id" ["d2706d2d-5454-4e37-b2c2-c66e0c14f368", 1, "joe", ~N[2020-06-12 03:15:42], ~N[2020-06-12 03:15:42]]
[debug] QUERY OK source="users" db=0.4ms queue=0.5ms idle=1065.2ms
SELECT u0."id", u0."invited_by_id", u0."invitation_accepted_at", u0."invitation_token", u0."password_hash", u0."username", u0."inserted_at", u0."updated_at" FROM "users" AS u0 WHERE (u0."id" = $1) [3]
[info] Sent 302 in 31ms
[info] GET /invitations/d2706d2d-5454-4e37-b2c2-c66e0c14f368
[debug] Processing with PowInvitation.Phoenix.InvitationController.show/2
  Parameters: %{"id" => "d2706d2d-5454-4e37-b2c2-c66e0c14f368"}
  Pipelines: [:browser]
[info] Sent 302 in 8ms
[debug] PowInvitation.Phoenix.InvitationController halted in :load_user_from_invitation_token/2

As the log says, the user is created in the database with the invitation_token shown in the log. However, attempting to actually use the token does not work, resulting in blocking with the login page if not logged in, and in the same error if logged in.

My Pow related routes are:

              pow_session_path  GET     /session/new                           Pow.Phoenix.SessionController :new
              pow_session_path  POST    /session                               Pow.Phoenix.SessionController :create
              pow_session_path  DELETE  /session                               Pow.Phoenix.SessionController :delete
         pow_registration_path  GET     /registration/edit                     Pow.Phoenix.RegistrationController :edit
         pow_registration_path  GET     /registration/new                      Pow.Phoenix.RegistrationController :new
         pow_registration_path  POST    /registration                          Pow.Phoenix.RegistrationController :create
         pow_registration_path  PATCH   /registration                          Pow.Phoenix.RegistrationController :update
                                PUT     /registration                          Pow.Phoenix.RegistrationController :update
         pow_registration_path  DELETE  /registration                          Pow.Phoenix.RegistrationController :delete
pow_invitation_invitation_path  GET     /invitations/:id/edit                  PowInvitation.Phoenix.InvitationController :edit
pow_invitation_invitation_path  GET     /invitations/new                       PowInvitation.Phoenix.InvitationController :new
pow_invitation_invitation_path  GET     /invitations/:id                       PowInvitation.Phoenix.InvitationController :show
pow_invitation_invitation_path  POST    /invitations                           PowInvitation.Phoenix.InvitationController :create
pow_invitation_invitation_path  PATCH   /invitations/:id                       PowInvitation.Phoenix.InvitationController :update
                                PUT     /invitations/:id                       PowInvitation.Phoenix.InvitationController :update

Most helpful comment

It's a bug in Pow, thanks for reporting it.

I've fixed it with #535 which has been merged into master. If you update the deps to pull from github ({:pow, github: "danschultzer/pow"}), then it should be working correctly now! Sorry for the trouble.

All 6 comments

You need to sign the invitation token with PowInvitation.Plug.sign_invitation_token/2

/invitations/d2706d2d-5454-4e37-b2c2-c66e0c14f368 this tells me that the token is not signed. This could be if you are using any custom code or just trying to make a request with the unsigned token.

I believe I am just attempting to make the request with the unsigned token, how would I go about signing it properly? I followed the documentation for setting up PowInvitation which does not mention signing the token.

This is using the built-in Plugs. The only alteration I've made is switching from an email to a username in the user schema.

Something like this should work.

PowInvitation.Plug.sign_invitation_token(@conn, user)

Something like this should work.

PowInvitation.Plug.sign_invitation_token(@conn, user)

But where would I put that line? And which account is user referencing, the new one or the existing one that created the invitation?

It's a bug in Pow, thanks for reporting it.

I've fixed it with #535 which has been merged into master. If you update the deps to pull from github ({:pow, github: "danschultzer/pow"}), then it should be working correctly now! Sorry for the trouble.

Oh, I thought I was just doing something wrong. Glad I opened this issue then. Thanks a ton for your fast response and fix @danschultzer! And thanks for your help too @Schultzer.

Was this page helpful?
0 / 5 - 0 ratings