Redirect after login

How to redirect users after login to custom resources based on user group and assigned resource group dynamically? I will have a lot of users and each one will have a user group with their unique resource group.
So each user when logged in should be redirected to their specific resource which is hidden from other users (their personal page). Each user has its own user group and resource group (with specific resource) assigned to its user group. I can’t hardcode redirect in login page since there is going to be more users added in the future. Searched the net for solution, but couldn’t find similar situation where’s that dynamicaly solved. It’s modx Revolution 3.0.4-pl! Any chance for help @bobray ? Thank you!

This is what I’ve tried so far snippet that is called &postHooks=landingPage

$userId = $modx->getUser()->get('id');

// Get the resource ID assigned to the user's group
$resourceId = $modx->getOption('resource_id', $scriptProperties);

// Check if the user has access to the specified resource
if ($modx->hasPermission('resource_view', $resourceId)) {
    // Redirect the user to the specific resource
} else {
    // Redirect to a default page or handle as needed
    $modx->sendRedirect($modx->makeUrl(2)); // Change 1 to the default resource ID

Is it just one page per user? If so, you could create a user setting with the page ID when the page is first saved with a plugin connected to OnDocFormSave and checking for modSystemEvent::MODE_NEW. Then use that setting to redirect them.

FYI, hasPermission() is a method of the user object and only takes one argument:


This will only check for context policies.

Object policies like “view” have to be checked with


I’m not sure either of these will work for you at login.

I think the user setting is your best bet.

1 Like

Thank you very much Bob I’ll give it a try.