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: Switch logto role assignment to subscription webhook [DEV-4164] #565

Merged
merged 12 commits into from
Aug 2, 2024

Conversation

jay-dee7
Copy link
Contributor

@jay-dee7 jay-dee7 commented Aug 1, 2024

This PR switches the user Logto role assignment logic.

Caution

  1. We do not assign a default Logto role anymore. Up until now, we were always assigning the Testnet Role by default to all users. This has been removed now.
  2. We do need to pre-seed the database now with Testnet and Mainnet Logto roles and switch the role Id for default role to use the Portal role

We now use the Portal role as the default role. We assign this role on Studio Portal, and as a fallback option, we also assign this role here. Double assigning does not have any side-effects.

We've now switched the logic to assign Logto roles based on user subscription. To achieve this, we now have two additional environment variables:

  1. LOGTO_TESTNET_ROLE_ID - Logto role ID for the Testnet role. This must be set in environment variables
  2. LOGTO_MAINNET_ROLE_ID - Logto role ID for the Mainnet role. This must be set in environment variables

This is the flow:

  1. Logto Webhook Handler
  • Handled events:
    • PostRegister
    • PostSignIn
  • If the user has an existing subscription, find the subscription record and assign a role based on the subscription
    • If on Build Plan, assign Mainnet, Testnet and Portal Logto roles
    • If on Test Plan, assign Testnet and Portal roles
  • If the user does not have a subscription, only assign the Portal Logto role
  • If the user already has the required roles, early return without assigning.
  1. Stripe Subscription Webhook Handler
  • Handled events:
    • customer.subscription.deleted
    • customer.subscription.created
    • customer.subscription.updated
  • For subscription create and update:
    • If on Build Plan, assign Mainnet, Testnet and Portal Logto roles
    • If on Test Plan, assign Testnet and Portal roles
  • For subscription deleted (cancel):
    • Remove all roles related to Test and Build plans (leaving Portal role)

@jay-dee7 jay-dee7 marked this pull request as draft August 1, 2024 11:18
Signed-off-by: jay-dee7 <me@jsdp.dev>
@jay-dee7 jay-dee7 force-pushed the feat/assign-logto-roles-on-subscription branch from b131d96 to 50a56d9 Compare August 1, 2024 12:12
Signed-off-by: jay-dee7 <me@jsdp.dev>
@jay-dee7 jay-dee7 force-pushed the feat/assign-logto-roles-on-subscription branch from 50a56d9 to 35fe107 Compare August 1, 2024 12:13
Signed-off-by: jay-dee7 <me@jsdp.dev>
@jay-dee7 jay-dee7 self-assigned this Aug 1, 2024
src/controllers/api/account.ts Outdated Show resolved Hide resolved
src/services/track/admin/subscription-submitter.ts Outdated Show resolved Hide resolved
src/services/track/admin/subscription-submitter.ts Outdated Show resolved Hide resolved
src/services/track/admin/subscription-submitter.ts Outdated Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Outdated Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Outdated Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Outdated Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Outdated Show resolved Hide resolved
@jay-dee7 jay-dee7 requested a review from ankurdotb August 2, 2024 07:13
@jay-dee7 jay-dee7 marked this pull request as ready for review August 2, 2024 07:13
@jay-dee7 jay-dee7 force-pushed the feat/assign-logto-roles-on-subscription branch 2 times, most recently from d4e9764 to 08f83ca Compare August 2, 2024 07:53
@jay-dee7 jay-dee7 changed the title feat: Switch logto role assignment to subscription webhook feat: Switch logto role assignment to subscription webhook - [DEV-4164] Aug 2, 2024
@ankurdotb
Copy link
Contributor

Signed-off-by: jay-dee7 <me@jsdp.dev>
@jay-dee7 jay-dee7 force-pushed the feat/assign-logto-roles-on-subscription branch from 08f83ca to dc12b8d Compare August 2, 2024 08:27
Signed-off-by: jay-dee7 <me@jsdp.dev>
@ankurdotb ankurdotb changed the title feat: Switch logto role assignment to subscription webhook - [DEV-4164] feat: Switch logto role assignment to subscription webhook [DEV-4164] Aug 2, 2024
.node-version Outdated Show resolved Hide resolved
src/controllers/api/account.ts Outdated Show resolved Hide resolved
src/middleware/auth/logto-helper.ts Show resolved Hide resolved
src/services/api/role.ts Show resolved Hide resolved
jay-dee7 and others added 5 commits August 2, 2024 17:10
Signed-off-by: jay-dee7 <me@jsdp.dev>
Signed-off-by: jay-dee7 <me@jsdp.dev>
Signed-off-by: jay-dee7 <me@jsdp.dev>
@ankurdotb ankurdotb merged commit 0b93908 into develop Aug 2, 2024
13 checks passed
@ankurdotb ankurdotb deleted the feat/assign-logto-roles-on-subscription branch August 2, 2024 14:14
cheqd-bot bot pushed a commit that referenced this pull request Aug 2, 2024
## [3.1.0-develop.3](3.1.0-develop.2...3.1.0-develop.3) (2024-08-02)

### Features

* Switch logto role assignment to subscription webhook [DEV-4164] ([#565](#565)) ([0b93908](0b93908))
@cheqd-bot
Copy link

cheqd-bot bot commented Aug 2, 2024

🎉 This PR is included in version 3.1.0-develop.3 🎉

The release is available on:

Your semantic-release bot 📦🚀

cheqd-bot bot pushed a commit that referenced this pull request Aug 5, 2024
## [3.1.0](3.0.0...3.1.0) (2024-08-05)

### Features

* Switch logto role assignment to subscription webhook [DEV-4164] ([#565](#565)) ([0b93908](0b93908))
* Synchronising stripe and studio API state - [DEV-4157] ([#561](#561)) ([f338db7](f338db7))

### Bug Fixes

* Return proper response on auth setup [DEV-4146] ([#560](#560)) ([690d854](690d854))
* trigger stripe account creation on sign-in ([#559](#559)) ([d2fec93](d2fec93))
* Use `admin:subscription:get` auth guard for Stripe checkout session ([#564](#564)) ([fc631e4](fc631e4))
@cheqd-bot
Copy link

cheqd-bot bot commented Aug 5, 2024

🎉 This PR is included in version 3.1.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@cheqd-bot cheqd-bot bot added the released label Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants