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

Login in with mbta_uuid #1449

Merged
merged 2 commits into from
Jun 17, 2024
Merged

Login in with mbta_uuid #1449

merged 2 commits into from
Jun 17, 2024

Conversation

ErinLMoore
Copy link
Contributor

@ErinLMoore ErinLMoore commented Jun 14, 2024

Asana ticket

Lets a user login in from keycloak if their user id matches either the sub id or the mbta_uuid. Does not log in and redirects to landing page if both are somehow found.

@ErinLMoore ErinLMoore changed the title Nil error elm Login in with mbta_uuid Jun 14, 2024
@ErinLMoore ErinLMoore force-pushed the nil-error-elm branch 4 times, most recently from bb1cb7f to 871882f Compare June 17, 2024 13:03
@ErinLMoore ErinLMoore requested a review from arkadyan June 17, 2024 13:18
@ErinLMoore ErinLMoore marked this pull request as ready for review June 17, 2024 14:43
Copy link
Collaborator

@arkadyan arkadyan left a comment

Choose a reason for hiding this comment

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

👍 A few small notes, but nothing major.

@@ -240,6 +240,15 @@ defmodule AlertProcessor.Model.User do
@spec get(id()) :: t() | nil
def get(id), do: Repo.get(__MODULE__, id)

@spec get_by_alternate_id(%{id: id() | nil, mbta_uuid: id() | nil}) :: [t()]
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): It might be helpful to have a quick description here describing how mbta_uuid is the old-style ID for accounts from the time before SSO.

@spec get_by_alternate_id(%{id: id() | nil, mbta_uuid: id() | nil}) :: [t()]
def get_by_alternate_id(%{id: id, mbta_uuid: mbta_uuid}) do
from(u in __MODULE__,
where: u.id in [^id, ^mbta_uuid]
Copy link
Collaborator

Choose a reason for hiding this comment

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

question: I think it will be possible for a little while for id and mbta_uuid to be the same value. If that's the case, will this just do the "right" think and return a single result (if there is one)? I'm guessing that's probably the case? Would it be worth a quick test case maybe just to demonstrate the possibility and show it behaving correctly?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was surprised, but Repo.all() apparently won't return duplicate records, so it does behave correctly in that case. I'll add a test around it.

conn
|> put_session("logout_uri", logout_uri)
|> SessionHelper.sign_in(user)
case user do
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion (non-blocking): If you were to move this case statement up so that it's examining the results of get_or_create_user, then you could skip a bunch of the following lines in the case where you get the result :find_user_error, and use_props_from_token wouldn't have to be changed to handle that case.

nil ->
# The user just created their account in Keycloak so we need to add them to our database
@spec get_or_create_user(
%{id: User.id() | nil, mbta_uuid: User.id() | nil},
Copy link
Collaborator

Choose a reason for hiding this comment

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

suggestion: I don't think id can ever be nil here, right? (Which is good, because otherwise you'd have to do something about it when you go to create a new account.) This also applies to User.get_by_alternate_id.

@ErinLMoore ErinLMoore force-pushed the nil-error-elm branch 2 times, most recently from aa23bf1 to 6400747 Compare June 17, 2024 18:07
@ErinLMoore ErinLMoore merged commit 4b64a8e into main Jun 17, 2024
7 checks passed
@ErinLMoore ErinLMoore deleted the nil-error-elm branch June 17, 2024 18:14
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