statamic / cms

The core Laravel CMS Composer package
https://statamic.com
Other
3.58k stars 490 forks source link

After switching to DB users, error if file users still exist #4498

Closed edalzell closed 7 months ago

edalzell commented 2 years ago

Bug description

I switch users over to the DB, then when you try to access the CP (I think) you get this error: https://github.com/statamic/cms/issues/719#issuecomment-943075400.

Removing the users (and no other changes) makes everything work.

How to reproduce

  1. Have a site with file based users
  2. Switch over to DB users, but leave the file users there
  3. access site/cp

Logs

No response

Versions

Statamic 3.2.16 Pro Laravel 8.64.0 PHP 8.0.11 aryehraber/statamic-captcha 1.5.2 aryehraber/statamic-uuid 2.0.3 doublethreedigital/duplicator 2.0.0 edalzell/forma 1.0 jonassiewertsen/statamic-livewire 2.7.0 statamic/seo-pro 2.3.2 transformstudios/blackbaud dev-main transformstudios/events 2.2.2 transformstudios/front 1.7.1 transformstudios/gated dev-main transformstudios/magic-link dev-main transformstudios/review 3.1 transformstudios/simple dev-main transformstudios/stripe dev-main transformstudios/takeover-redirects dev-main

Installation

Fresh statamic/statamic site via CLI

Additional details

No response

joseph-d commented 2 years ago

I can confirm a similar thing happening when you try to run php please stache:clear or other stache commands, the error is as follows:

Call to undefined method Statamic\Auth\Eloquent\User::initialPath()

  at vendor/statamic/cms/src/Stache/Stores/UsersStore.php:39

..as with the original report, I am getting this on a site that I switched over from file-based users to database-based users. Deleting the file-based user's yaml files stops the error from appearing.

sineld commented 2 years ago

This line worked for me:

Deleting the file-based user's yaml files stops the error from appearing

ryanmitchell commented 2 years ago

I think the issue may be with the docs on this... on this page it says "In config/statamic/stache.php, comment out the users store."

That means the stache config still has a users key as it gets it from core... really what you need to do is set directory in the users key to null, and then these commands work fine.

mattkibbler commented 2 years ago

I also had this problem when switching from file-based users to database.

The line in the documentation "In config/statamic/stache.php, comment out the users store" was confusing because the stores array in my config/statamic/stache.php file is empty.

However, I can confirm that deleting any remaining yaml files for each user does stop the Call to undefined method Statamic\Auth\Eloquent\User::initialPath() error from happening.

sineld commented 1 year ago

Adding this method to User model solves issue for me:

public function isSuper()
{
    return $this->super;
}