cms icon indicating copy to clipboard operation
cms copied to clipboard

Can't login to cp when setting statamic guard for cp users

Open edulazaro opened this issue 4 years ago • 3 comments

Bug description

I move it here, as it seems to happen to more users.

The login box does nohing when trying to login. The password check seems to happen, as the login box only trembles with a wrong password. With a correct password, the page refreshes and nothing happens.

Have followed the steps here: https://statamic.dev/tips/using-an-independent-authentication-guard Also explained here: https://statamic.com/forum/4942-existing-app-with-solo-user-but-multiple-users-in-db

The pro is enabled.

When creating the ser directly using the yaml file, the password gets encrypted and a user id is generated correctly, but can't still login.

No errors into the logs at all.

Thanks : )

How to reproduce

Install statamic on an existing laravel 8 app and configure statamic guard for cp users.

config/statamic/users.php

    'repository' => 'file',

    'repositories' => [

        'file' => [
            'driver' => 'file',
            'paths' => [
                'users' => base_path('users'),
                'roles' => resource_path('users/roles.yaml'),
                'groups' => resource_path('users/groups.yaml'),
            ],
        ],

        'eloquent' => [
            'driver' => 'eloquent',
        ],

    ],
    /* .. */.
    'guards' => [
        'cp' => 'statamic',
        'web' => 'web',
    ],

config/auth.php

    'guards' => [
        'api' => [
            'driver' => 'passport',
            'provider' => 'users',
        ],
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
    	'statamic' => [
          'driver' => 'session',
          'provider' => 'statamic',
    	]
    ],

    'providers' => [
        'users' => [
            'driver' => 'eloquent',
            'model' => App\Models\User::class,
        ],
       'statamic' => [
            'driver' => 'statamic',
        ],
    ],

config/statamic/stache.php

'stores' => [
       /*  ...  */
        'users' => [
            'class' => Stores\UsersStore::class,
            'directory' => base_path('users'),
        ],

]

Logs

No response

Versions

Laravel 8 Latest statamic 3 version

Installation

Existing Laravel app

Additional details

No response

edulazaro avatar Jan 07 '22 16:01 edulazaro

Can you provide a repo with this problem reproduced so we can investigate?

jasonvarga avatar Jan 07 '22 16:01 jasonvarga

Can you provide a repo with this problem reproduced so we can investigate?

Yes; just a laravel + livewire fresh install + statamic, with the statamic guard

https://github.com/edulazaro/larastatamic

edulazaro avatar Jan 07 '22 17:01 edulazaro

I had similar trouble with a Fresh Statamic install with statamic-cli. I followed this guide exactly: https://statamic.dev/tips/using-an-independent-authentication-guard

The first problem was that my password was hashed and saved incorrectly during the cli installation. That might be a windows issue as the prompt says 'Password (Your input will be hidden)' when in fact the input was visible. Anyway, my password was saved incorrectly in the yaml file so I manually copied the hash value from another project to fix it.

The second thing I had to do was run php artisan config:clear because my password reset form kept looking in the eloquent database.

Also, I noticed another thing. Your config above shows:

'guards' => [
  'cp' => 'statamic',
  'web' => 'web',
],

When this guide says it should be:

'guards' => [
  'cp' => 'statamic',
  'web' => 'statamic',
],

You might have a different issue but maybe this will help.

stuartcusackie avatar Sep 06 '22 14:09 stuartcusackie

Any updates on this? Having the same issue with Laravel 10 and Statamic 4

nickashley avatar Nov 30 '23 23:11 nickashley

@nickashley there are some updated docs being worked on - https://github.com/statamic/docs/pull/1139 - maybe check those out to make sure you've covered everything.

ryanmitchell avatar Dec 01 '23 06:12 ryanmitchell

This issue is relatively old now and I'm not able to reproduce this on a fresh site.

We've recently updated our docs around configuring independent auth guards, which adds some more clarity to some steps in the process.

I'm going to close this issue now. If anyone's still having issues, please open a new issue and we can take a look.

duncanmcclean avatar Jan 17 '24 12:01 duncanmcclean