Skip to main content

Home Page Redirection

SoftyFlow provides a powerful home page redirection system that allows administrators to automatically redirect users to specific pages based on their roles, metadata, and custom conditions. This feature enables personalized user experiences and ensures users land on the most relevant page for their context.

Overview

The home page redirection system works by evaluating JavaScript conditions against user data when a user accesses the home page (/home). If a condition evaluates to true, the user is automatically redirected to the specified page instead of the default home page.

Key Features

  • Role-based redirection: Route users based on their assigned roles
  • Metadata filtering: Use custom user metadata for conditional routing
  • JavaScript expressions: Write complex conditions using JavaScript
  • Priority ordering: Control rule evaluation order
  • Project-specific pages: Redirect to pages within specific projects

How It Works

When a user accesses the home page, the system:

  1. Loads all configured redirection rules from settings
  2. Evaluates each rule in order of priority
  3. Executes the JavaScript condition with user context
  4. Redirects to the first matching rule's target page
  5. Falls back to default home page if no rules match

User Context Variables

The redirection system provides access to user information through the SF_connectedUser object:

SF_connectedUser = {
mail: "user@example.com", // User's email address
roles: ["role_id_1", "role_id_2"], // Array of role IDs
metadata: { // User metadata object
department: "IT",
isManager: "yes",
location: "Paris"
},
represent: { // Delegation information
users: ["delegate@example.com"],
roles: ["delegated_role_id"]
}
}

Configuration

Accessing Redirection Settings

  1. Navigate to Settings in the IDE
  2. Select Header from the settings panel
  3. View the Homepage section with redirection rules

Creating Redirection Rules

Step 1: Add a New Rule

  1. Click Create Rule button
  2. A new rule entry appears in the rules table
  3. Click the Settings icon to configure the rule

Step 2: Configure Rule Components

Project Selection

  • Choose the project containing the target page
  • Use the searchable dropdown to find projects
  • This determines which project's pages are available

Page Selection

  • Select the target page/interface from the chosen project
  • Only pages within the selected project are shown
  • The user will be redirected to this page if the condition matches

Rule Condition

  • Write a JavaScript expression that returns true or false
  • Use SF_connectedUser to access user data
  • The condition determines when this redirection applies

Step 3: Set Rule Priority

  • Use the up/down arrows in the Sort column
  • Rules are evaluated from top to bottom
  • First matching rule wins - subsequent rules are ignored
  • Place more specific rules higher in the list

Rule Examples

Basic Role-Based Redirection

// Redirect administrators to admin dashboard
SF_connectedUser.roles.includes('admin_role_id')

// Redirect managers to management interface
SF_connectedUser.roles.includes('manager_role_id')

// Redirect users with multiple roles
SF_connectedUser.roles.includes('hr_role_id') || SF_connectedUser.roles.includes('finance_role_id')

Metadata-Based Redirection

// Redirect based on department
SF_connectedUser.metadata.department === "IT"

// Redirect managers to special dashboard
SF_connectedUser.metadata.isManager === "yes"

// Redirect based on location
SF_connectedUser.metadata.location === "Paris"

// Complex metadata conditions
SF_connectedUser.metadata.department === "Sales" && SF_connectedUser.metadata.level === "Senior"

Email-Based Redirection

// Redirect specific users
SF_connectedUser.mail === "ceo@company.com"

// Redirect based on email domain
SF_connectedUser.mail.endsWith("@contractors.com")

// Redirect external users
!SF_connectedUser.mail.endsWith("@company.com")

Combined Conditions

// Redirect IT managers
SF_connectedUser.metadata.department === "IT" && SF_connectedUser.roles.includes('manager_role_id')

// Redirect senior staff or managers
SF_connectedUser.metadata.level === "Senior" || SF_connectedUser.metadata.isManager === "yes"

// Redirect based on multiple criteria
SF_connectedUser.roles.includes('project_lead_id') &&
SF_connectedUser.metadata.location === "HQ" &&
SF_connectedUser.metadata.clearanceLevel >= 3

Advanced Examples

// Redirect based on role count
SF_connectedUser.roles.length > 2

// Redirect users with delegation rights
SF_connectedUser.represent.users.length > 0

// Redirect based on metadata existence
SF_connectedUser.metadata.hasOwnProperty('specialAccess')

// Time-based redirection (using external data)
dataa.SF_mode === 'prod' && SF_connectedUser.roles.includes('prod_user_id')

Best Practices

Rule Organization

  1. Order by Specificity: Place more specific rules first

    // More specific - should be first
    SF_connectedUser.mail === "admin@company.com"

    // Less specific - should be later
    SF_connectedUser.roles.includes('admin_role_id')
  2. Use Descriptive Conditions: Write clear, readable conditions

    // Good
    SF_connectedUser.metadata.department === "Finance" && SF_connectedUser.metadata.isManager === "yes"

    // Avoid
    SF_connectedUser.metadata.d === "F" && SF_connectedUser.metadata.m === "y"
  3. Test Conditions: Verify rules work as expected before deployment

Performance Considerations

  1. Minimize Rule Count: Use fewer, well-crafted rules rather than many simple ones
  2. Efficient Conditions: Place faster-evaluating conditions first in complex expressions
  3. Avoid Heavy Operations: Don't perform complex calculations in conditions

Security Guidelines

  1. Validate User Data: Don't assume metadata values are always present

    // Safe
    SF_connectedUser.metadata && SF_connectedUser.metadata.department === "IT"

    // Risky
    SF_connectedUser.metadata.department === "IT"
  2. Use Role IDs: Reference roles by ID rather than name for consistency

  3. Sanitize Inputs: Be cautious with user-provided metadata values

Troubleshooting

Common Issues

Rule Not Triggering

  • Check rule order - ensure it's not being overridden by earlier rules
  • Verify condition syntax is valid JavaScript
  • Confirm user has expected roles/metadata
  • Check that target page exists and is accessible

Infinite Redirects

  • Ensure target page doesn't have its own redirection rule
  • Verify conditions are mutually exclusive
  • Check for circular redirection patterns

JavaScript Errors

  • Validate condition syntax in browser console
  • Check for undefined variables or properties
  • Use safe property access with && operators

Debugging Tips

  1. Test Conditions in Browser Console:

    // Simulate user object
    const SF_connectedUser = {
    mail: "test@company.com",
    roles: ["user_role_id"],
    metadata: { department: "IT" }
    };

    // Test your condition
    console.log(SF_connectedUser.metadata.department === "IT");
  2. Use Browser Developer Tools: Monitor network requests to see redirection behavior

  3. Check Server Logs: Look for redirection-related log entries

Integration with Home.vue

The redirection system integrates with the Home.vue component in the IDE, which provides the settings interface for managing redirection rules. The component allows administrators to:

  • Create and edit redirection rules
  • Test JavaScript conditions with syntax highlighting
  • Manage rule priority and ordering
  • Select target projects and pages

Code Integration

The redirection logic is implemented in the addHeaderRules function in the serve controller:

const addHeaderRules = async (variables) => {
let page = ''
await Settings.findOne({})
.then((data) => {
for (let i = 0; i < data.rules.length; i++) {
if (new Function(...Object.keys(variables), "dataa", 'return ' + data.rules[i].rule)(...Object.values(variables), variables)) {
page = data.rules[i].page
break;
}
}
})
return page
}

This function evaluates each rule's condition and returns the target page ID for the first matching rule.

Conclusion

Home page redirection provides a powerful way to create personalized user experiences in SoftyFlow. By leveraging user roles, metadata, and custom conditions, administrators can ensure users are automatically directed to the most relevant content for their context and responsibilities.

Remember to test redirection rules thoroughly and maintain clear documentation of your redirection logic for future maintenance and troubleshooting.