Auth driver [ldap-session] for guard [ldap] is not defined #5207

Closed
opened 2026-02-05 09:48:19 +03:00 by OVERLORD · 9 comments
Owner

Originally created by @513ry on GitHub (Mar 4, 2025).

Describe the Bug

When using Illuminate\Support\Facades\Auth::user() I get following error:

In AuthManager.php line 99:

  Auth driver [ldap-session] for guard [ldap] is not defined.

Cleaning catch and configuration with artisan does not work as it return the same error.

LDAP works otherwise for login and other BookStack features.

Steps to Reproduce

  1. We set up LDAP following ldap-auth documentation.
  2. Add a new logical theme
  3. Call Illuminate\Support\Facades\Auth::user() inside functions.php of that theme

Expected Behaviour

Get current user to filter database query.

Screenshots or Additional Context

No response

Browser Details

No response

Exact BookStack Version

v24.05.4

Originally created by @513ry on GitHub (Mar 4, 2025). ### Describe the Bug When using `Illuminate\Support\Facades\Auth::user()` I get following error: ``` In AuthManager.php line 99: Auth driver [ldap-session] for guard [ldap] is not defined. ``` Cleaning catch and configuration with artisan does not work as it return the same error. LDAP works otherwise for login and other BookStack features. ### Steps to Reproduce 1. We set up LDAP following [ldap-auth documentation](https://www.bookstackapp.com/docs/admin/ldap-auth/). 2. Add a new logical theme 3. Call `Illuminate\Support\Facades\Auth::user()` inside functions.php of that theme ### Expected Behaviour Get current user to filter database query. ### Screenshots or Additional Context _No response_ ### Browser Details _No response_ ### Exact BookStack Version v24.05.4
OVERLORD added the 🐕 Support label 2026-02-05 09:48:19 +03:00
Author
Owner

@ssddanbrown commented on GitHub (Mar 4, 2025):

Hi @513ry,

This could occur if attempting to get the user before the AuthServiceProvider has booted.
This could occur in your theme if you're attempting to get the user in the app_boot event (or within the global top-level space of the functions.php file).

Should work though if you're attempting to the the user within any other theme event.

If you think these is an issue, feel free to provide an example functions.php file which can be used to replicate the issue.

@ssddanbrown commented on GitHub (Mar 4, 2025): Hi @513ry, This could occur if attempting to get the user before the AuthServiceProvider has booted. This could occur in your theme if you're attempting to get the user in the app_boot event (or within the global top-level space of the functions.php file). Should work though if you're attempting to the the user within any other theme event. If you think these is an issue, feel free to provide an example `functions.php` file which can be used to replicate the issue.
Author
Owner

@513ry commented on GitHub (Mar 4, 2025):

Thank you for your answer @ssddanbrown.

I moved the Auth::user() call after route callback (Route::get) and LDAP seems okay now. Although Auth::user() have returned null. Similar the session::all() array is empty. Should I verify the user inside another event?

@513ry commented on GitHub (Mar 4, 2025): Thank you for your answer @ssddanbrown. I moved the `Auth::user()` call after route callback (`Route::get`) and LDAP seems okay now. Although `Auth::user()` have returned `null`. Similar the `session::all()` array is empty. Should I verify the user inside another event?
Author
Owner

@ssddanbrown commented on GitHub (Mar 4, 2025):

@513ry It depends on what you're attempting to do. It comes down to timing since some things can run before the auth/session has performed its own setup.

All of the main theme events provided, aside from APP_BOOT (and maybe WEB_MIDDLEWARE_BEFORE?), should be after any active user/auth session handling is done, so calls to the user within callback of those should work be fine.

BTW, there is a global user() helper function which is what I mostly use in-app: 13dae24cbe/app/App/helpers.php (L33-L40)

This will default to the guest user, where not logged in, which can be handy in many cases.

@ssddanbrown commented on GitHub (Mar 4, 2025): @513ry It depends on what you're attempting to do. It comes down to timing since some things can run before the auth/session has performed its own setup. All of the main theme events provided, aside from APP_BOOT (and maybe WEB_MIDDLEWARE_BEFORE?), should be after any active user/auth session handling is done, so calls to the user within callback of those should work be fine. BTW, there is a global `user()` helper function which is what I mostly use in-app: https://github.com/BookStackApp/BookStack/blob/13dae24cbe3f95ba6747f1ffe37bc3e1a4db4af9/app/App/helpers.php#L33-L40 This will default to the guest user, where not logged in, which can be handy in many cases.
Author
Owner

@ssddanbrown commented on GitHub (Mar 4, 2025):

Also, if you're adding custom routes at the top level, you might not have the required session/auth middlware active.
We expose the ROUTES_REGISTER_WEB and ROUTES_REGISTER_WEB_AUTH to make registering routes easier for a normal web context (with active sessions and middlware).

An example can be seen here:
https://www.bookstackapp.com/blog/bookstack-release-v23-12/#logical-theme-system-events-to-register-routes

@ssddanbrown commented on GitHub (Mar 4, 2025): Also, if you're adding custom routes at the top level, you might not have the required session/auth middlware active. We expose the `ROUTES_REGISTER_WEB` and `ROUTES_REGISTER_WEB_AUTH` to make registering routes easier for a normal web context (with active sessions and middlware). An example can be seen here: https://www.bookstackapp.com/blog/bookstack-release-v23-12/#logical-theme-system-events-to-register-routes
Author
Owner

@513ry commented on GitHub (Mar 4, 2025):

I been not adding the route at the top level, I used the APP::BOOT event. Thanks, that is a much better approach!

@513ry commented on GitHub (Mar 4, 2025): I been not adding the route at the top level, I used the `APP::BOOT` event. Thanks, that is a much better approach!
Author
Owner

@513ry commented on GitHub (Mar 4, 2025):

Do you have maybe an example of how filtering a queue by user id is generally done?

@513ry commented on GitHub (Mar 4, 2025): Do you have maybe an example of how filtering a queue by user id is generally done?
Author
Owner

@ssddanbrown commented on GitHub (Mar 4, 2025):

Do you have maybe an example of how filtering a queue by user id is generally done?

I'm not sure what you mean by that, what queue is that specifically referring to?

@ssddanbrown commented on GitHub (Mar 4, 2025): > Do you have maybe an example of how filtering a queue by user id is generally done? I'm not sure what you mean by that, what queue is that specifically referring to?
Author
Owner

@513ry commented on GitHub (Mar 5, 2025):

Sorry, I meant database "query". From my understanding scopes('visible') does only return the public properties of an Entity. Right?

@513ry commented on GitHub (Mar 5, 2025): Sorry, I meant database "query". From my understanding `scopes('visible')` does only return the public properties of an `Entity`. Right?
Author
Owner

@513ry commented on GitHub (Mar 5, 2025):

Well, this is out of the initial subject of this issue. PermissionApplicator was what I been looking for (more specific restrictEntityQuery).

@513ry commented on GitHub (Mar 5, 2025): Well, this is out of the initial subject of this issue. `PermissionApplicator` was what I been looking for (more specific [restrictEntityQuery](https://github.com/BookStackApp/BookStack/blob/13dae24cbe3f95ba6747f1ffe37bc3e1a4db4af9/app/Permissions/PermissionApplicator.php#L100)).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/BookStack#5207