Feature/68 add edit user#75
Open
Berny-ft wants to merge 4 commits into
Open
Conversation
Add server actions and Zod schemas for creating and updating users via Supabase Admin API, with profile sync in Drizzle. Add create/edit dialogs and wire the table edit action to EditUserDialog.
Add subscription_months to the create-user flow and grantComplimentarySubscription via STRIPE_PRICE_ID trial. Treat trialing subscriptions as active in the users list and return a generic error when Stripe grant fails after user creation.
Add AlertDialog confirmation before create and save. Remount form state on dialog close so errors and inputs reset. Align action errors with login/discounts patterns and block Stripe-internal messages from the UI. Place Add user above filters with brand styling.
There was a problem hiding this comment.
Pull request overview
Adds admin-facing user management under /users, including creating new users (optionally with complimentary Stripe trial months) and editing existing users’ email/role, backed by new server actions and supporting UI dialogs.
Changes:
- Added admin server actions (
createUserAdmin,updateUserAdmin) with Zod validation and Supabase Admin API integration. - Added Stripe helper to grant complimentary subscription trials and updated user listing to treat
trialingas Active. - Implemented Create/Edit user dialogs and wired the table “edit” (pencil) action to open the edit flow.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| utils/supabase/admin.ts | Adds a Supabase Admin client factory for server-side admin operations. |
| lib/stripe.ts | Adds complimentary subscription grant helper and sync step. |
| components/ui/alert-dialog.tsx | Introduces shadcn-style AlertDialog component for confirmation modals. |
| app/(authenticated)/users/schema.ts | Adds Zod schemas for create/update admin user actions. |
| app/(authenticated)/users/queries.ts | Treats trialing subscription status as Active in the users list. |
| app/(authenticated)/users/actions.ts | Implements admin create/update user server actions (Supabase + Drizzle + Stripe trial grant). |
| app/(authenticated)/users/_components/users-columns.tsx | Refactors columns into a factory and wires edit button click handling. |
| app/(authenticated)/users/_components/users-client.tsx | Adds Create/Edit dialogs and connects edit action state to the table. |
| app/(authenticated)/users/_components/user-admin-dialog.tsx | Implements the Create User and Edit User dialog UIs with confirmation prompts. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| const admin = createAdminClient(); | ||
| const { error: authError } = await admin.auth.admin.updateUserById( | ||
| user_id, | ||
| { email, app_metadata: { user_role: role } }, |
| updatedAt: new Date(), | ||
| }, | ||
| }); | ||
| } catch { |
Comment on lines
+168
to
+174
| } catch { | ||
| return { | ||
| errors: { | ||
| _form: [ | ||
| "User was created, but the complimentary subscription could not be added. Please try again or contact support.", | ||
| ], | ||
| }, |
Comment on lines
+355
to
+359
| limit: 1, | ||
| }); | ||
|
|
||
| const status = existing.data[0]?.status; | ||
| if (status === "active" || status === "trialing") { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #68
Overview
Admins can manage users from
/users: create accounts with email, password, name, and role, optionally grant complimentary subscription months (Stripe trial onSTRIPE_PRICE_ID), and edit existing users’ email and role from the table pencil action.Backend
createUserAdmin/updateUserAdminserver actions with Zod validation andrequireAdmin()createUser/updateUserById) andprofilessync in DrizzlelistUsersWithEmails()joinsauth.usersfor real emails and subscription status for Active/InactivegrantComplimentarySubscription()for optional trial months;syncStripeDatakeepssubscriptionsin syncFrontend
#0040A1alert-dialogcomponent added for confirmationsEnv / setup:
SUPABASE_SECRET_KEY(admin client) andSTRIPE_PRICE_IDmust be set; Stripe product/price must be active for complimentary grants to succeed.Testing
Manually tested the creation and the modification of users.
Screenshots / Screencasts
when you modify the user's email it won't update on the stripe side; I'm not sure that is needed since there's an id tying the two together
Checklist