Skip to content

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Jetstream & Custom auth guard #4683

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
georgecoca opened this issue Aug 10, 2022 · 5 comments · Fixed by laravel/jetstream#1120
Closed

Jetstream & Custom auth guard #4683

georgecoca opened this issue Aug 10, 2022 · 5 comments · Fixed by laravel/jetstream#1120

Comments

@georgecoca
Copy link

  • Laravel Version: 9.24.0
  • Nova Version: 4.12.14
  • Laravel JetStream: 2.11.0

Description:

If the application has JetStream installed and configured a custom auth guard with a provider eloquent (example: App/Models/Admin) when authenticating in Nova it throws an error:

Call to undefined method App\Models\Admin::allTeams()

Which seems that in Nova the middleware \Laravel\Jetstream\Http\Middleware\ShareInertiaData is loaded too which causes the issue.

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

  1. Have JetStream installed
  2. Create a custom auth guard
  3. Set the guard in nova config as the default
  4. Authenticate in Nova
  5. Error occurs.
@crynobone
Copy link
Member

crynobone commented Aug 10, 2022

  1. Nova only use default authentication requirements. allTeams() is a specific feature on Jetstream and if there an exception it's definitely coming from Jetstream and not Nova.
  2. Nova doesn't use \Laravel\Jetstream\Http\Middleware\ShareInertiaData and doesn't a need for it.
  3. Have you verify you have Jetstream installed correctly? Default installation with --team should add all the correct traits to the user model.

Please provide the full reproducing repository similar to https://github.com/nova-issues in order for us to debug the issue.

@crynobone crynobone added the needs more info More information is required label Aug 10, 2022
@georgecoca
Copy link
Author

@crynobone thanks for your reply.

  1. That's correct, but as both packages are maintained by Laravel, I suppose they should work together.
  2. That's correct, Nova doesn't need it but when you are in Nova because JetStream is installed it also loads that middleware automatically.
  3. As I've mentioned in the description, in my particular case I created a new model Admin which doesn't use the HasTeams trait. I already have an User model that uses the HasTeams trait, but for accessing Nova only Admin is allowed.

I hope this clarifies better the issue. Thank you.

@crynobone
Copy link
Member

This is not a Nova bug and you're using Jetstream incorrectly. Submit a request to Jetstream to support using multiple User model where one doesn't use Team feature when configured with Team feature.

@crynobone crynobone closed this as not planned Won't fix, can't repro, duplicate, stale Aug 11, 2022
@georgecoca
Copy link
Author

@crynobone thanks again for your response. Indeed it's not a bug of Nova but it seems Jetstream doesn't play well if I have a custom model for other purposes (in this case for Nova). Closing this and hopefully will find a solution.

@georgecoca
Copy link
Author

@crynobone I've been thinking that Nova could handle this situation easily. We just need a custom config to specify which middlewares we want to be removed from Nova routes. See below example:

vendor/laravel/nova/src/PendingRouteRegistration.php

Route::namespace('Laravel\Nova\Http\Controllers')
            ->domain(config('nova.domain', null))
            ->middleware(config('nova.middleware', []))
            ->withoutMiddleware(config('nova.withoutMiddleware', []))  <-- new addition

config/nova.php

    'withoutMiddleware' => [
        \Laravel\Jetstream\Http\Middleware\ShareInertiaData::class,
    ],

Same for api_middleware.

This can help unload specific middlewares that are injected by other packages installed in Laravel. I think it would be a great solution not only for this specific case but for others too. What do you think? Thanks.

@georgecoca georgecoca reopened this Aug 11, 2022
@crynobone crynobone removed the needs more info More information is required label Aug 12, 2022
@laravel laravel locked and limited conversation to collaborators Aug 12, 2022
@crynobone crynobone converted this issue into discussion #4692 Aug 12, 2022
crynobone added a commit to crynobone/jetstream that referenced this issue Aug 12, 2022
information.

This would be useful for application with multiple user providers and uses
Inertia. As an example, this will fixes laravel/nova-issues#4683

Signed-off-by: Mior Muhammad Zaki <[email protected]>
taylorotwell added a commit to laravel/jetstream that referenced this issue Aug 17, 2022
…formation. (#1120)

* Check current model supports HasTeams before trying to access team
information.

This would be useful for application with multiple user providers and uses
Inertia. As an example, this will fixes laravel/nova-issues#4683

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

* formatting

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
growno1127 added a commit to growno1127/jetstream that referenced this issue Mar 15, 2024
…formation. (#1120)

* Check current model supports HasTeams before trying to access team
information.

This would be useful for application with multiple user providers and uses
Inertia. As an example, this will fixes laravel/nova-issues#4683

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

* formatting

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>
panich76 added a commit to panich76/jetstream that referenced this issue Mar 5, 2025
…formation. (#1120)

* Check current model supports HasTeams before trying to access team
information.

This would be useful for application with multiple user providers and uses
Inertia. As an example, this will fixes laravel/nova-issues#4683

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* wip

* formatting

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Taylor Otwell <[email protected]>

This issue was moved to a discussion.

You can continue the conversation there. Go to discussion →

Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants