fix(session panic): check if nil before use
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
leo 2023-05-16 13:49:02 +02:00
parent ad6bcac326
commit be1709794a
Signed by: wanderer
SSH Key Fingerprint: SHA256:Dp8+iwKHSlrMEHzE3bJnPng70I7LEsa3IJXRH/U+idQ
2 changed files with 12 additions and 12 deletions

@ -15,15 +15,15 @@ func Admin() echo.HandlerFunc {
func Index() echo.HandlerFunc {
return func(c echo.Context) error {
sess, _ := session.Get(setting.SessionCookieName(), c)
username := sess.Values["username"]
if username != nil {
return c.Redirect(http.StatusFound, "/home")
}
addHeaders(c)
if sess, _ := session.Get(setting.SessionCookieName(), c); sess != nil {
username := sess.Values["username"]
if username != nil {
return c.Redirect(http.StatusFound, "/home")
}
}
csrf := c.Get("csrf").(string)
err := c.Render(

@ -17,11 +17,11 @@ func Signin() echo.HandlerFunc {
return func(c echo.Context) error {
addHeaders(c)
sess, _ := session.Get(setting.SessionCookieName(), c)
username := sess.Values["username"]
if username != nil {
return c.Redirect(http.StatusFound, "/home")
if sess, _ := session.Get(setting.SessionCookieName(), c); sess != nil {
username := sess.Values["username"]
if username != nil {
return c.Redirect(http.StatusFound, "/home")
}
}
return c.Render(