Skip to content

Commit 3656a2a

Browse files
authored
Fix goth user infer bug (#15821)
1 parent e5723d6 commit 3656a2a

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

routers/user/auth.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -983,11 +983,16 @@ func LinkAccountPostRegister(ctx *context.Context) {
983983
ctx.Data["SignInLink"] = setting.AppSubURL + "/user/link_account_signin"
984984
ctx.Data["SignUpLink"] = setting.AppSubURL + "/user/link_account_signup"
985985

986-
gothUser := ctx.Session.Get("linkAccountGothUser")
987-
if gothUser == nil {
986+
gothUserInterface := ctx.Session.Get("linkAccountGothUser")
987+
if gothUserInterface == nil {
988988
ctx.ServerError("UserSignUp", errors.New("not in LinkAccount session"))
989989
return
990990
}
991+
gothUser, ok := gothUserInterface.(goth.User)
992+
if !ok {
993+
ctx.ServerError("UserSignUp", fmt.Errorf("session linkAccountGothUser type is %t but not goth.User", gothUserInterface))
994+
return
995+
}
991996

992997
if ctx.HasError() {
993998
ctx.HTML(http.StatusOK, tplLinkAccount)
@@ -1049,7 +1054,7 @@ func LinkAccountPostRegister(ctx *context.Context) {
10491054
}
10501055
}
10511056

1052-
loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.(goth.User).Provider)
1057+
loginSource, err := models.GetActiveOAuth2LoginSourceByName(gothUser.Provider)
10531058
if err != nil {
10541059
ctx.ServerError("CreateUser", err)
10551060
}
@@ -1061,10 +1066,10 @@ func LinkAccountPostRegister(ctx *context.Context) {
10611066
IsActive: !(setting.Service.RegisterEmailConfirm || setting.Service.RegisterManualConfirm),
10621067
LoginType: models.LoginOAuth2,
10631068
LoginSource: loginSource.ID,
1064-
LoginName: gothUser.(goth.User).UserID,
1069+
LoginName: gothUser.UserID,
10651070
}
10661071

1067-
if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, gothUser.(*goth.User), false) {
1072+
if !createAndHandleCreatedUser(ctx, tplLinkAccount, form, u, &gothUser, false) {
10681073
// error already handled
10691074
return
10701075
}

0 commit comments

Comments
 (0)