From 1713beb73b661f4c95074a9e0a67435e5881af87 Mon Sep 17 00:00:00 2001 From: KN4CK3R Date: Wed, 19 Oct 2022 21:07:21 +0200 Subject: [PATCH] Suppress `ExternalLoginUserNotExist` error (#21504) Fixes #21202 Closes #21276 An `ExternalLoginUser` is not mandatory if the current user account was created with/by the external login source. --- routers/web/auth/auth.go | 6 +++++- routers/web/auth/oauth.go | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index 8a4c12d57b..b48bdb9951 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -6,6 +6,7 @@ package auth import ( + "errors" "fmt" "net/http" "strings" @@ -24,6 +25,7 @@ import ( "code.gitea.io/gitea/modules/session" "code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/timeutil" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/modules/web" "code.gitea.io/gitea/modules/web/middleware" "code.gitea.io/gitea/routers/utils" @@ -619,7 +621,9 @@ func handleUserCreated(ctx *context.Context, u *user_model.User, gothUser *goth. // update external user information if gothUser != nil { if err := externalaccount.UpdateExternalUser(u, *gothUser); err != nil { - log.Error("UpdateExternalUser failed: %v", err) + if !errors.Is(err, util.ErrNotExist) { + log.Error("UpdateExternalUser failed: %v", err) + } } } diff --git a/routers/web/auth/oauth.go b/routers/web/auth/oauth.go index c172215b90..e0e3c6e59f 100644 --- a/routers/web/auth/oauth.go +++ b/routers/web/auth/oauth.go @@ -1068,7 +1068,9 @@ func handleOAuth2SignIn(ctx *context.Context, source *auth.Source, u *user_model // update external user information if err := externalaccount.UpdateExternalUser(u, gothUser); err != nil { - log.Error("UpdateExternalUser failed: %v", err) + if !errors.Is(err, util.ErrNotExist) { + log.Error("UpdateExternalUser failed: %v", err) + } } if err := resetLocale(ctx, u); err != nil {