Skip to content

[Bug]: Unable to change auth guard from web #61

@Muffinman

Description

@Muffinman

What happened?

In some scenarios it would be beneficial to specify the auth guard that can be used to authenticate users with Vantage. Specifically if you have a separate set of frontend users and admin users, with different auth guards.

Currently this isn't possible.

Perhaps something like this would be possible?

class AuthorizeVantage
{
    /**
     * Handle an incoming request.
     *
     * @param  Closure(Request): (Response)  $next
     */
    public function handle(Request $request, Closure $next): Response
    {
        // Try to resolve the authenticated user via the configured or default guard
        $user = Auth::guard(config('vantage.auth.guard'))->user() ?? Auth::user();

        // Authorization is fully handled by the Gate
        // The Gate accepts a null user and performs its own logic
        if (! Gate::forUser($user)->allows('viewVantage', $user)) {
            abort(403, 'Unauthorized access to Vantage dashboard.');
        }

        return $next($request);
    }
}

Vantage config:

...
    'auth' => [
        'enabled' => env('VANTAGE_AUTH_ENABLED', true),
        'guard' => env('VANTAGE_AUTH_GUARD', 'web'),
    ],
...

How to reproduce the bug

1 .Create another separate auth guard (leave web as default)
2, Attempt to authorise the user against the non-default guard

Package Version

0.1.24

PHP Version

8.4.18

Laravel Version

12.55.1

Which operating systems does this happen with?

No response

Notes

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions