Skip to content

Cannot redirect user based on role #5708

@HeadStudios

Description

@HeadStudios

Description:

I am attempting to redirect a user based on role (I use Spatie) on their first login however no matter what I try nothing seems to work - I have tried register() function in Nova Service Provider as suggested in docs however this is not redirecting me:

public function register()
    {
    
                $user = request()->user();
    
                if ($user) {
                    if ($user->hasRole('super-admin')) {
                        dump("You are super!");
                        Nova::initialPath('/resources/campaigns');
                    } elseif ($user->hasRole('importer')) {
                        dump("Come in importer!");
                        Nova::initialPath('/csv-import');
                    } else {
                        // default path for other roles
                        Nova::initialPath('/resources/users');
                    }
                }

    }

The dump is coming through but the user is still going to dashboard by default. Thank you!

Detailed steps to reproduce the issue on a fresh Nova installation:

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions