From 945a2a29dd6d3b1b493e5e3f6dc1a1e80ad331e8 Mon Sep 17 00:00:00 2001 From: Andrea Fazzi Date: Mon, 18 Nov 2019 10:51:44 +0100 Subject: [PATCH] Display user name only if claims are not nil --- renderer/renderer.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/renderer/renderer.go b/renderer/renderer.go index e4443e9c..980030d6 100644 --- a/renderer/renderer.go +++ b/renderer/renderer.go @@ -247,7 +247,9 @@ func (rend *HTMLRenderer) Render(w http.ResponseWriter, r *http.Request, data in rend.writeError(w, r, &htmlTemplateData{err, nil}) } - log.Println("Current user is", r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)["name"]) + if r.Context().Value("user") != nil { + log.Println("Current user is", r.Context().Value("user").(*jwt.Token).Claims.(jwt.MapClaims)["name"]) + } w.Header().Set("Content-Type", "text/html; charset=utf-8") err := t.ExecuteTemplate(w, options[0]["tpl_layout"][0], &htmlTemplateData{data, options[0]})