Advisor/client invite system
How advisors can invite and manage their clients.
Overview
The advisor/client invite system enables financial advisors to invite their clients to the platform and manage their financial portfolios. This feature introduces a new relationship model where:
- Advisors can register with a specialized account type
- Advisors can create and prepare client spaces before client acceptance
- Advisors can invite multiple clients to the platform
- Clients get their own dedicated spaces that are linked to their advisor's subscription
- Advisors can access and manage their clients' financial data
- The application UI adapts contextually based on the user's role (advisor or client)
This document details the technical implementation of this feature, including database structure, authentication flows, and user interface components.
System architecture
Database schema
The advisor/client system builds on the existing space and subscription models with these key additions:
-
Space enhancement
- Added
is_advisorboolean flag to thespacetable to distinguish advisor spaces - Modified space creation logic in
handle_new_profilefunction to set this flag based on signup type - Added
space_for_client_emailfield to track prepared spaces that haven't been accepted yet
- Added
-
Advisor subscription items
- New
advisor_subscription_itemtable that creates a many-to-one relationship between client spaces and an advisor's subscription - This enables a single advisor subscription to cover multiple client spaces
- New
-
Modified invite system
- Added
invite_typeto track advisor-specific invites - Updated
accept_invitefunction to handle different invitation types - Added support for prepared client spaces that exist before client acceptance
- Added
-
User spaces view
- Provides a unified view of all spaces a user has access to
- Includes context information (
space_context) that determines the UI experience - Identifies relationships between advisors and clients
- Supports the new prepared client space context
User roles and space contexts
The system introduces several new roles and contexts:
-
User roles
owner: The creator of a space (either individual or advisor)advisor: An advisor managing a client's spaceclient: A client in their own space being managed by an advisormember: A regular member in a space (from the existing system)
-
Space contexts (from the
user_spacesview)advisor_space: Advisor's own space where they manage their businessindividual: Regular user's personal spaceclient_space: Client space that has an advisor relationship and has been accepted by the clientprepared_client_space: Client space created by an advisor but not yet accepted by the clientinactive: Space without an active subscription
The space context determines the user experience and is calculated based on role, subscription status, and the presence of advisor relationships.
Advisor workflow
Creating prepared client spaces
Advisors can now create and prepare client spaces before clients accept invitations:
-
Creating a prepared space
- Advisor navigates to their dashboard
- Clicks "Add client" button to open the prepare space dialog
- Enters the client's email address and other required information
- System validates the email (must be unique, properly formatted)
-
Setting up the space
- System creates a new client space with
space_for_client_emailset to the provided email - This space has a context of
prepared_client_space - The space is linked to the advisor's subscription via an
advisor_subscription_item - The space appears in the advisor's dashboard immediately
- System creates a new client space with
-
Working in the prepared space
- Advisor can immediately access and start working in the prepared space
- They can configure portfolios, add assets, and set up the space for the client
- All data entered is preserved for when the client eventually accepts the invitation
Inviting clients
Advisors can invite clients to join their prepared spaces:
-
Inviting to existing prepared space
- When creating a prepared space, an invitation is automatically created
- The system associates the invitation with the prepared space via the client email
- Email is sent to the client with a signup/acceptance link
-
Creating the invitation
- System creates a record in
group_invitetable withinvite_typeset to "advisor_client" - The invitation includes a reference to the prepared space
- System creates a record in
Managing client spaces
Advisors can now:
- View both prepared client spaces and active client spaces in the advisor dashboard
- Switch between their own space, prepared client spaces, and active client spaces
- Begin managing financial data in prepared spaces before client acceptance
- See which spaces are prepared and which are active based on visual indicators
The advisor dashboard is rendered when:
- The user has an advisor space (where
is_advisoris true) - The user's selected space is their advisor space
- The user has client spaces and/or prepared client spaces linked through
advisor_subscription_item
// Logic determining when to show advisor dashboard (simplified)
function shouldShowAdvisorDashboard() {
return (
(profile.selectedSpaceId === null ||
userSpaces.find((space) => space.spaceId === profile.selectedSpaceId)
?.spaceContext === "advisor_space") &&
userSpaces[0].spaceContext === "advisor_space"
);
}Client workflow
Accepting invitations
When a client receives an invitation to a prepared space, they follow these steps:
-
Accessing the invitation
- Client clicks the link in the invitation email
- System validates the invite status
- The invite type is captured and passed to the signup flow
-
Registration flow
- For new users: Client completes the signup form
- The system stores both
invite_idandinvite_typein the user's metadata - For existing users: Client logs in to their account
-
Space assignment
- The system identifies the prepared space associated with the client's email
- The prepared space is converted to an active client space (
client_spacecontext) - Client is added as role
clientto their space - The prepared data remains intact and available to the client immediately
Using client space
Once the invitation is accepted:
- Client has access to their own financial dashboard with all the data prepared by their advisor
- Client can see their advisor has access to their space
- All activities in the client space are visible to both client and advisor
Technical implementation details
User spaces view
The user_spaces view has been enhanced to support prepared client spaces by distinguishing between regular client spaces and prepared client spaces based on whether the space_for_client_email field is populated.
The space context determines the appropriate UI to display and is calculated based on:
- The user's role in the space
- The subscription status and relationship
- Whether the space has been accepted by a client (via the
space_for_client_emailfield)
Accept invite function
The accept invite process has been updated to handle prepared spaces, checking if there's an existing prepared space for the client's email before creating a new one. When a prepared space is found, it's converted to a regular client space instead of creating a new one.
Signup form enhancements
The signup form has been enhanced to properly handle redirects for prepared spaces:
// Simplified example of the updated useEffect in SignUpForm component
useEffect(() => {
if (form.formState.isSubmitSuccessful) {
if (state.redirect && state.reauthenticate) {
reauthenticate()
.then(() => {
// Success - we're authenticated
router.push(state.redirect as string);
})
.catch(() => {
toast.error(t("SignUp.Form.reauthenticationError"));
// Reset the ref so we can try again if needed
hasRedirected.current = false;
});
} else if (state.redirect) {
// Direct redirect without reauthentication
router.push(state.redirect);
}
}
}, [state.redirect, state.reauthenticate, form, router, t]);This ensures that:
- Redirects work properly whether reauthentication is required or not
- Users are always directed to the appropriate space after signup
- The flow works correctly for both prepared spaces and regular invitations
User interface components
Advisor dashboard
The advisor dashboard has been enhanced to provide a unified view of all client spaces:
- Shows both active client spaces and prepared client spaces in a unified grid
- Visually distinguishes between active and prepared spaces
- Provides a way to create new prepared spaces
- Allows switching between all space types
Prepare space dialog
The new PrepareSpaceDialog replaces the previous AddClientDialog:
- Collects client email and optionally other information
- Validates input for correctness
- Creates a prepared space immediately
- Sends an invitation to the client
- Returns the user to the dashboard where the new prepared space is visible
Client space and prepared space components
The system includes specialized components for different space types:
-
AdvisorClientSpace component
- Displays active client spaces with client name and email
- Provides visual indicators of the space status
- Handles space switching when clicked
-
AdvisorPreparedSpace component
- Displays prepared client spaces with space name and client email
- Uses distinct visual styling to indicate prepared status
- Handles space switching when clicked
These components ensure that advisors can easily distinguish between different space types while maintaining a consistent interface for interaction.
Client space navigation
When an advisor accesses any client space (prepared or active):
- The UI reflects the specific type of space they are viewing
- They have the ability to switch back to their advisor space
- They can perform actions based on the space context
Best practices and considerations
Security
- Invitations are validated through secure tokens
- Client data is protected by row-level security policies
- Role-based access controls ensure appropriate permissions
- Prepared spaces maintain proper ownership until client acceptance
Subscription management
- Advisor subscriptions are billed based on the number of client spaces, including prepared spaces
- Subscription items maintain the relationship between spaces
- Stripe integration handles proper billing
User experience
- The application adapts its UI based on space context
- Advisors have clear indicators when working in different space types
- Clients see appropriate information about their advisor relationship
- Prepared spaces allow advisors to set up client environments in advance
Conclusion
The enhanced advisor/client system with prepared spaces creates a powerful relationship model that enables financial advisors to start managing client portfolios immediately, without waiting for client acceptance. Advisors can now:
- Create dedicated client spaces in advance
- Configure and populate these spaces with relevant financial data
- Send invitations to clients to join their prepared spaces
- Manage both prepared and active client spaces from a unified dashboard
This implementation extends the existing database structures while adding specialized components to handle the unique requirements of prepared spaces. The result is a more efficient workflow for advisors and a better experience for clients, who gain access to fully configured spaces upon acceptance.