PHP code example of geniusauth / laravel

1. Go to this page and download the library: Download geniusauth/laravel library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

geniusauth / laravel example snippets


Route::middleware('geniusauth')->group(function () {
    Route::get('/dashboard', [DashboardController::class, 'index']);
    Route::get('/account', [AccountController::class, 'show']);
    Route::post('/settings', [SettingsController::class, 'update']);
});

use GeniusAuth\Laravel\Facades\GeniusAuth;

Route::get('/sign-in', fn () => GeniusAuth::redirect())->name('sign-in');

$user = GeniusAuth::user();

// [
//     'id'     => 'usr_abc123',
//     'email'  => '[email protected]',
//     'name'   => 'Alice',
//     'claims' => [...all OIDC claims],
// ]

GeniusAuth::logout();
return redirect('/');

use GeniusAuth\Laravel\Facades\GeniusAuthLink;

// Sync the current OIDC user to GeniusAuth
$result = GeniusAuthLink::syncToGeniusAuth(
    externalUserId: '123',
    phone: '+2250701020304',
    email: '[email protected]',
    name: 'Alice',
    phoneVerified: true,
);

// Look up a user by GeniusID
$user = GeniusAuthLink::lookupByGeniusId('@2250701020304');

use GeniusAuth\Laravel\Facades\GeniusAuth;
use Illuminate\Http\Request;

class AuthController
{
    public function signIn()
    {
        return GeniusAuth::redirect();
    }

    public function dashboard(Request $request)
    {
        $user = GeniusAuth::user();

        return view('dashboard', ['user' => $user]);
    }

    public function logout()
    {
        GeniusAuth::logout();

        return redirect()->route('home');
    }
}

use GeniusAuth\Laravel\Contracts\UserRepositoryInterface;

$this->app->bind(UserRepositoryInterface::class, App\Repositories\GeniusAuthUserRepository::class);