fix oauth login

This commit is contained in:
xiaomlove
2025-05-02 22:04:00 +07:00
parent 8f4a6cf50c
commit 7ef23bcc6b
3 changed files with 14 additions and 14 deletions

View File

@@ -89,10 +89,21 @@ class OauthController extends Controller
$response = Http::withToken($tokenInfo['access_token'])->get($provider->user_info_endpoint_url);
$userInfo = $response->json();
do_log("userInfo: " . $response->body());
$homeUrl = getSchemeAndHttpHost() . "/index.php";
$providerUserId = data_get($userInfo, $provider->id_claim);
if (empty($providerUserId)) {
throw new NexusException(nexus_trans('oauth.get_provider_user_id_error', ['id_claim' => $provider->id_claim]));
}
$socialAccount = SocialAccount::query()
->where('provider_id', $provider->id)
->where('provider_user_id', $providerUserId)
->first();
if ($socialAccount) {
//already bind, login directly
$authUser = $socialAccount->user;
logincookie($authUser->id, $authUser->auth_key);
return redirect($homeUrl);
}
$providerEmail = data_get($userInfo, $provider->email_claim);
if (empty($providerEmail)) {
throw new NexusException(nexus_trans('oauth.get_provider_email_error', ['email_claim' => $provider->email_claim]));
@@ -104,17 +115,7 @@ class OauthController extends Controller
}
$providerUsername = data_get($userInfo, $provider->username_claim);
$providerLevel = data_get($userInfo, $provider->level_claim);
$homeUrl = getSchemeAndHttpHost() . "/index.php";
$socialAccount = SocialAccount::query()
->where('provider_id', $provider->id)
->where('provider_user_id', $providerUserId)
->first();
if ($socialAccount) {
//already bind, login directly
$authUser = $socialAccount->user;
logincookie($authUser->id, $authUser->auth_key);
return redirect($homeUrl);
}
$minLevel = $provider->level_limit;
if ($minLevel) {
if (!$providerLevel) {

View File

@@ -18,7 +18,6 @@ class NexusFormatter
if (nexus()) {
$id = nexus()->getRequestId();
}
$id .= " -> " . getLogFile();
$format = "[%datetime%] [" . $id . "] %channel%.%level_name%: %message% %context% %extra%\n";
return tap(new LineFormatter($format, 'Y-m-d H:i:s', true, true), function ($formatter) {
$formatter->includeStacktraces();

View File

@@ -17,7 +17,7 @@ return [
|
*/
'default' => env('LOG_CHANNEL', 'daily'),
'default' => env('LOG_CHANNEL', 'single'),
/*
|--------------------------------------------------------------------------
@@ -37,7 +37,7 @@ return [
'channels' => [
'stack' => [
'driver' => 'stack',
'channels' => ['daily'],
'channels' => ['single'],
'ignore_exceptions' => false,
],