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

Fix the auth helpers to only require fields they need from AuthIdentity #2057

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

Conversation

infomiho
Copy link
Contributor

@infomiho infomiho commented May 24, 2024

The auth helpers like getEmail and getUsername didn't work unless you provided the full user object with full AuthIdentity objects in the identities array.

Given that we suggest to users to include only the providerName and providerUserId when manually fetching the user + auth + identities, we should make sure our auth helpers work in that scenario.

This PR:

  • makes it so that they only need to pass in the providerName and providerUserId when using the helpers.
  • includes a headless test to ensure this helper works in the future.

Signed-off-by: Mihovil Ilakovac <mihovil@ilakovac.com>
@@ -130,6 +132,8 @@ const TaskView = ({ task }: { task: Task }) => {
}
}

const email = getEmail(task.user)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Using the helper in the headless tests.

@@ -30,7 +30,7 @@ genAuth spec =
Just auth ->
-- shared stuff
sequence
[ genUserTs
[ genFileCopy [relfile|auth/user.ts|]
Copy link
Contributor Author

Choose a reason for hiding this comment

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

No need for templating anymore for this file, I've used a copy file draft instead.

@infomiho infomiho changed the title Improve the auth helpers by making the input types as minimal as needed Fix the auth helpers to only require only fields they need from AuthIdentity May 24, 2024
@infomiho infomiho changed the title Fix the auth helpers to only require only fields they need from AuthIdentity Fix the auth helpers to only require fields they need from AuthIdentity May 24, 2024
@Martinsos Martinsos requested a review from sodic May 24, 2024 17:26
@infomiho infomiho added the auth label Jun 5, 2024
return tasks
}
}) satisfies GetTasks<void>
Copy link
Contributor

@sodic sodic Jun 10, 2024

Choose a reason for hiding this comment

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

How come the frontend type tests aren't complaining about this?

Different todoApp. Boy, they really are diverging 😅

Copy link
Contributor

@sodic sodic left a comment

Choose a reason for hiding this comment

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

This is always a good thing to do in TypeScript (use the structural type system define arguments to have as few constraints as possible).

There's also an item in Effective TypeScript that talks about it.

One thing I'd possibly like changed. If the MinimalUserEntityWithAuth is the type users will be seeing the most of, I recommend flipping the naming:

  • Change MinimalUserEntityWithAuth to UserEntityWithAuth
  • Change UserEntityWithAuth to something more verbose.

@infomiho
Copy link
Contributor Author

infomiho commented Jun 19, 2024

Good point! The tricky part with the UserEntityWithAuth name is that it is correct in a sense that it represents a tree of full Prisma entities. The second type is derived from it by making it as minimal as possible to make the function as flexible as possible.

The problem is that the user will see this wacky (albeit correct) name, and we want to do better.

Some alternatives:

  • internal: CompleteUserEntityWithAuth, public: UserEnittyWithAuth
  • internal AuthEntityTree, public: UserEnittyWithAuth
  • internal: UserEntityWithAuthFields, public: UserWithRequiredAuthFields

I maybe like the first option the best since it's just a Complete vs nothing which gives us the relationship you suggested.

@infomiho infomiho requested a review from sodic June 21, 2024 09:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants