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

downgrade userId #138

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft

downgrade userId #138

wants to merge 7 commits into from

Conversation

ianmacartney
Copy link
Contributor

Just exploring what it'd look like if userId was a string with a few annotations on the edges


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Copy link

vercel bot commented Dec 12, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
convex-auth-docs ✅ Ready (Inspect) Visit Preview Dec 12, 2024 10:15pm

Copy link

pkg-pr-new bot commented Dec 12, 2024

npm i https://pkg.pr.new/get-convex/convex-auth/@convex-dev/auth@138

commit: 74aace4

Comment on lines +33 to +36
UserDocument extends Record<string, Value> = DocumentByName<
DataModel,
"users"
>,
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 wonder if we should just have this be the same as other providers, vs. returning a specific type.. not sure if this is causing the type issues

Comment on lines -69 to +75
const { user } = await createAccount(ctx, {
const { account } = await createAccount(ctx, {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

one concern is that folks who have made their own providers may be tripped up by createAccount not returning the user anymore. This would be a breaking change technically

export interface PasswordConfig<DataModel extends GenericDataModel> {
export interface PasswordConfig<
DataModel extends GenericDataModel,
UsersTable extends TableNamesInDataModel<DataModel> = "users",
Copy link
Contributor Author

Choose a reason for hiding this comment

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

could just do the UsersDoc like anonymous to be more flexible, but not sure which is more convenient / types better

Comment on lines -63 to -64
// TODO: Ian removed this
user: (await ctx.db.get(existingAccount.userId))!,
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 don't remember why this was added back. I thought it wasn't needed beyond getting the userId, but there's a decent amount of untyped code..

ctx.db.normalizeId("users", existingUserId) === null
) {
throw new Error(
`User ID \`${existingUserId}\` is not in the \`users\` table`,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could use a better message about defining your own createOrUpdateUser to use another table

Comment on lines -344 to +346
export type ConvexCredentialsConfig = ConvexCredentialsUserConfig<any> & {
export type ConvexCredentialsConfig<
DataModel extends GenericDataModel = GenericDataModel,
> = ConvexCredentialsUserConfig<DataModel> & {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

this type might be why there's now circular types issues..?

@thomasballinger
Copy link
Contributor

the proposal here (based on this PR and chatting in person) is

  • ConvexAuthConfig is parameterized by a string type, Id<"users"> by default. Any use of GenericId<"users"> is now this type, which doesn't even need to be an Id or refer to a table at all.
  • Functions like upsertUserAndAccount and invalidateSessions that accepted GenericId<"users"> now accept a string
  • We want functions like getAuthUserId that returned GenericId<"users"> to return a string, but that's not backward-compatible, so we add an optional type parameter that is still GenericId<"users"> by default.

This makes it possible to change the name of the "users" table by

  • passing a different ID type to ConvexAuthConfig
  • wrapping getAuthUserId in a helper that casts it to your new ID type
  • passing a createOrUpdateUser callback which returns a GenericId<"myOtherUsersTable">

This also makes the advanced use case of completely customizing how users are stored possible (maybe they're in two tables, it's they're in an external system, etc.) by

  • passing a string type instead of an ID type to ConvexAuthConfig
  • passing a createOrUpdateUser callback which returns a string instead of a GenericId<"users">

As a long-term goal, if all interaction with the users table is developer-mediated then there are no Convex Auth-imposed constraints on the users table. Assumptions about the users table (described here) wouldn't be needed.

@thomasballinger
Copy link
Contributor

We'll also want to make writing a createOrUpdateUser callback simpler if we do this.

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