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

feat(user, types): add invite and user properties + migration #6327

Merged
merged 19 commits into from
Feb 14, 2024

Conversation

pKorsholm
Copy link
Contributor

What

  • Add invite model
  • Populate user model

@pKorsholm pKorsholm requested review from a team as code owners February 6, 2024 11:35
Copy link

vercel bot commented Feb 6, 2024

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

Name Status Preview Comments Updated (UTC)
medusa-dashboard ✅ Ready (Inspect) Visit Preview 💬 Add feedback Feb 14, 2024 1:47pm
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
api-reference ⬜️ Ignored (Inspect) Feb 14, 2024 1:47pm
docs-ui ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2024 1:47pm
medusa-docs ⬜️ Ignored (Inspect) Visit Preview Feb 14, 2024 1:47pm

Copy link

changeset-bot bot commented Feb 6, 2024

🦋 Changeset detected

Latest commit: d04316f

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@medusajs/core-flows Patch
@medusajs/medusa Patch
@medusajs/types Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
expression: `create unique index "invite_user_identifier_index" on "invite" ("user_identifier") where deleted_at is null;`,
})
@Property({ columnType: "text" })
user_identifier: string
Copy link
Collaborator

Choose a reason for hiding this comment

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

think it is reasonable to just stick with email. Flow would be something like this:

  1. User invites new user - enters their email.
  2. New user receives invite link on email with a token.
  3. If user wants to authenticate with e.g. Google they complete sign in flow.
  4. Once authenticated with Google they pass the invite token as part of the user creation call.
  5. AuthUser is associated with the new User.

I.e., the email is not used to tie a the AuthUser's entity id, but simply ensures there is a trusted destination the invite token can be sent to.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Email-password could also be facilitated through the user creation request with an additional step in the workflow to create the auth user.

packages/types/src/user/common.ts Outdated Show resolved Hide resolved
packages/types/src/user/common.ts Outdated Show resolved Hide resolved
packages/types/src/user/common.ts Outdated Show resolved Hide resolved
packages/types/src/user/mutations.ts Outdated Show resolved Hide resolved
packages/types/src/user/common.ts Outdated Show resolved Hide resolved
packages/user/src/models/user.ts Outdated Show resolved Hide resolved
packages/user/src/models/invite.ts Outdated Show resolved Hide resolved
packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
.changeset/tame-kings-battle.md Outdated Show resolved Hide resolved
)

const originalUsers = await service.list({
id: input.map((u) => u.id),
Copy link
Member

Choose a reason for hiding this comment

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

suggestion: For safety guard, as I have seen it occured in the modules, I would store the ids separately and then id ids.length then call the lists and the update wdyt?

packages/core-flows/src/user/workflows/create-users.ts Outdated Show resolved Hide resolved
packages/user/src/models/user.ts Outdated Show resolved Hide resolved
@PrimaryKey({ columnType: "text" })
id!: string

@Property({ columnType: "text", nullable: true })
Copy link
Member

Choose a reason for hiding this comment

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

todo(maybe): if a user is searchable by text search then add GIN index on first and last name. but you tell me

packages/user/src/models/user.ts Show resolved Hide resolved
packages/user/src/services/user-module.ts Show resolved Hide resolved
packages/user/src/services/user-module.ts Outdated Show resolved Hide resolved
@olivermrbl
Copy link
Contributor

olivermrbl commented Feb 14, 2024

@adrien2p, would it be possible to have you review this one? Would like to see if we can get #6395 merged today too.

Copy link
Member

@adrien2p adrien2p left a comment

Choose a reason for hiding this comment

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

LGTM 🔥

packages/types/src/user/common.ts Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants