-
-
Notifications
You must be signed in to change notification settings - Fork 158
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
How to Sign a Token on LiveView #642
Comments
This also doesn't work:
|
Hot dizzle dang! A new error!
|
I assume, in retrospect, that it's decoding that with a something that's signed with PowInvitation.Plug on the way back in. |
You got it right, but I would just do this: signed_token =
%Plug.Conn{secret_key_base: UserDocsWeb.Endpoint.config(:secret_key_base)}
|> Pow.Plug.put_config(otp_app: :my_app)
|> PowInvitation.Plug.sign_invitation_token(user) I've thought of letting these functions accept a module instead, so you could do this: signed_token = PowInvitation.Plug.sign_invitation_token(UserDocsWeb.Endpoint, user) Phoenix uses this extensively, and it would make it much easier to use Pow in cases where you don't have a
This would mean that you don't have a |
Yes, that last error was trivial for me to figure out. I've got the whole thing up and running. I'll try it with your suggestion |
Small correction, it was Now I get I assume I just need to fetch the pow config and place it on this artificial Conn. |
Good catch, updated the example! |
@danschultzer I solved it this way:
Is the eventual play to just put all the stuff you need on the socket, and access |
I'm using your implementation instead. Looks better to me. |
Here's my PowInvitation implementation in LiveView. Omitting front end, and some implementation specific stuff: User clicks "Send Invitation" on the form, it hits the send invitation envent:
Domain Functions:
|
Basically, it signs the token, hydrates the email on the form, then sends the email + db stuff to the backend. I probably could have put PowInvitation in there, but it's not super transparent to me without using the vanilla controllers. |
I believe all the plug functions should accept a module atom along with conn to make this easier. This is how Phoenix does it. That way you can just do: PowInvitation.Plug.sign_invitation_token(MyAppWeb.Endpoint, user) This would probably be the cleanest approach. Thanks for providing the working code! |
Howdy, I'm trying to get PowInvitation working on LiveView. I'm on the home stretch. I've got everything working except for accepting the final invitation. The error I get is "Invitation doesn't exist." From reading other issues I deduced that it's because I'm not signing the token properly. This rip isn't working either, but I think I'm close. I think I'm sourcing my signing salt from the wrong place:
The text was updated successfully, but these errors were encountered: