Browse Source

explore: panic if search without login (#3088)

Unknwon 7 years ago
parent
commit
e6df2259ab
1 changed files with 5 additions and 1 deletions
  1. 5 1
      routers/home.go

+ 5 - 1
routers/home.go

@@ -75,9 +75,13 @@ func RenderRepoSearch(ctx *context.Context, opts *RepoSearchOptions) {
 		}
 		count = opts.Counter(opts.Private)
 	} else {
+		var ctxUserID int64
+		if ctx.IsSigned {
+			ctxUserID = ctx.User.ID
+		}
 		repos, count, err = models.SearchRepositoryByName(&models.SearchRepoOptions{
 			Keyword:  keyword,
-			UserID:   ctx.User.ID,
+			UserID:   ctxUserID,
 			OrderBy:  opts.OrderBy,
 			Private:  opts.Private,
 			Page:     page,