Hello!
I’m currently setting up my phoenix backend to allow for signup with google oauth. After the user has successfully authenticated with google I create the user in the DB. The last step is to create a refresh token, place it in the DB, place the user id in their session and add the refresh token to a cookie.
This last step seems like a good candidate for a plug since it’s taking a connection, performing some work, modifying the connection session and then returning it. However it has to run after the action and not before which doesn’t seem to be the normal use case for plugs.
I had looked into Plug.Conn.register_before_send however this doesn’t work as my plug needs the user ID and I can’t find a way to pass that information from the action to my plug (conn.assigns didn’t work since I need to call register_before_send before I can add the value to conn.assigns)
So my question is:
Should I just put this work in a function plug and invoke it directly inside my controller action, or is there a nicer way to accomplish it?
Extra info:
- This functionality has to be reused in a few places so I can’t just put it in my controller action.
Thanks in advance for the help