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

magic link authentication for phx.gen.live #1

Open
wants to merge 17 commits into
base: main
Choose a base branch
from

Conversation

SteffenDE
Copy link
Owner

No description provided.

lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved

case Accounts.update_user_password(user, password, user_params) do
case Accounts.apply_user_password(user, user_params) do
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is necessary because we want to disconnect existing LiveView connections when a password is changed (we already invalidate the sessions). This is not happening at the moment, which could be a security risk. The problem with the old setup (changing the password in the LiveView) is that we clear the tokens when changing the password, so this is also the moment where we need to broadcast disconnects for all old sessions. Broadcasting here would break the flow though, because the current LiveView would be disconnected before it has a chance to actually handle the trigger_submit. Instead of doing a "disconnect everything except me" which would require us to know the session token in the LiveView, we instead move the actual password change mechanism to the controller and only validate here.

lib/auth_app_web/router.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
lib/auth_app/accounts.ex Outdated Show resolved Hide resolved
@SteffenDE SteffenDE marked this pull request as ready for review February 10, 2025 10:30
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

Successfully merging this pull request may close these issues.

2 participants