<?php
declare(strict_types=1);
require_once __DIR__.'/../../../_runtime.php';
$config=require __DIR__.'/bootstrap.php';
try {
    $provider=(string)($socialProvider??''); $request=array_merge($_GET,$_POST);
    $identity=(new \PpPhp\Generated\SocialAuth\SocialAuthManager($config))->complete($provider,$request);
    $user=(new \PpPhp\Generated\SocialAuth\SocialAccountService($config))->authenticate($identity);
    $_SESSION['_flash']=['message'=>'Welcome, '.htmlspecialchars((string)($user['fullname']?:$user['username'])).'!','type'=>'success']; header('Location: '.APP_BASE.'/'); exit;
} catch (\Throwable $e) { \PpPhp\Core\Events::fire('global.auth.socialLoginFailed',['provider'=>$socialProvider??'','reason'=>$e->getMessage()]); $_SESSION['_flash']=['message'=>$e->getMessage(),'type'=>'danger']; header('Location: '.APP_BASE.'/generated/auth/login.php'); exit; }
