egs33 / laravel-datastore-auth
Requires
- php: ^7.1
- google/cloud-datastore: ^1.5
- laravel/framework: ^5.5.0 || ^6.0.0 || ^7.0.0 || ^8.0.0
Requires (Dev)
- google/cloud-datastore: ^1.5.6
- guzzlehttp/guzzle: >=6.3.0
- mockery/mockery: ^1.1
- orchestra/testbench: >=3.5
- phpunit/phpunit: ^6.0 || ^7.0 || ^8.0
README
Laravel authentication using Google Datastore
Requirements
- Laravel >= 5.5.0
- Composer
Installation
$ composer require egs33/laravel-datastore-auth
$ php artisan vendor:publish --provider="DatastoreAuth\DatastoreAuthServiceProvider"
Quick Start
Set authentication driver to datastore
.
For example, in config/auth.php
'providers' => [ 'users' => [ 'driver' => 'datastore' ] ],
Then it can use same as Laravel authentication
Usage
Create user
$userConfig = [ 'name' => 'hoge', 'email' => 'hoge@example.com', 'password' => 'secret' ]; $userProvider = Auth::createUserProvider('users'); $userProvider->create($userConfig); // or DatastoreAuth::create($userConfig);
Get Current User etc.
Use Auth
facade.
Same as Laravel authentication
$user = Auth::user(); // get current user $isLoggedIn = Auth::check();
Update User Data
$user['name'] = 'new-name'; $user['group'] = 'new-group'; $user->save();
Config
Config file is config/datastore_auth.php
Default is
[ 'client_config' => [], 'kind' => 'users', 'cache' => [ 'isEnabled' => false, 'keyPrefix' => \DatastoreAuth\DatastoreUserProvider::class . ':', 'ttl' => null, ] ]
client_config
is passed to constructor of Google\Cloud\Datastore\DatastoreClient
.
Please see document of google/cloud-datastore
.
kind
is kind name of user table.
Cache
The cache is only used when fetch user by id.
Cache storage is specified by config/cache.php
in your laravel project.
ttl
is expressed in seconds regardless of the laravel version.
If it's null, no expire.
When DatastoreUserProvider#resetPassword
, DatastoreUserProvider#save
, DatastoreUserProvider#updateRememberToken
or User#save
is called, cache is cleared.
But you can call DatastoreUserProvider#deleteCache
if necessary.