aboutsummaryrefslogtreecommitdiff
path: root/cmd/web/middleware/auth.go
diff options
context:
space:
mode:
authorSamuel Johnson <[email protected]>2025-11-25 20:52:35 -0500
committerSamuel Johnson <[email protected]>2025-11-25 20:52:35 -0500
commit44d6620b32f31c04663c9e08a1c3954273230ee8 (patch)
treea87cf977313ec95f050d7cdbbebd8bdae7c00ab2 /cmd/web/middleware/auth.go
parent12602302f28478a9e4ef91e66f68347a4d76f8a6 (diff)
Tidy the code
Diffstat (limited to 'cmd/web/middleware/auth.go')
-rw-r--r--cmd/web/middleware/auth.go66
1 files changed, 33 insertions, 33 deletions
diff --git a/cmd/web/middleware/auth.go b/cmd/web/middleware/auth.go
index 255f40f..e396e86 100644
--- a/cmd/web/middleware/auth.go
+++ b/cmd/web/middleware/auth.go
@@ -10,12 +10,12 @@ import (
type AuthMiddleware struct {
Err *log.Logger
- Db *sql.DB
+ Db *sql.DB
}
func (auth *AuthMiddleware) CheckAndInvalidate(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(
- func (w http.ResponseWriter, r *http.Request) {
+ func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("paterissa_session_token")
if err != nil {
next.ServeHTTP(w, r)
@@ -25,11 +25,11 @@ func (auth *AuthMiddleware) CheckAndInvalidate(next http.HandlerFunc) http.Handl
stmt, err := auth.Db.Prepare("SELECT * FROM cookies WHERE content = $1;")
if err != nil {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)
@@ -47,11 +47,11 @@ func (auth *AuthMiddleware) CheckAndInvalidate(next http.HandlerFunc) http.Handl
err = row.Scan(&id, &content, &userId, &expiration)
if err != nil {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)
@@ -61,11 +61,11 @@ func (auth *AuthMiddleware) CheckAndInvalidate(next http.HandlerFunc) http.Handl
if time.Now().After(expiration) {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)
@@ -80,7 +80,7 @@ func (auth *AuthMiddleware) CheckAndInvalidate(next http.HandlerFunc) http.Handl
func (auth *AuthMiddleware) Resolve(next http.HandlerFunc) http.HandlerFunc {
return http.HandlerFunc(
- func (w http.ResponseWriter, r *http.Request) {
+ func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie("paterissa_session_token")
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
@@ -91,11 +91,11 @@ func (auth *AuthMiddleware) Resolve(next http.HandlerFunc) http.HandlerFunc {
stmt, err := auth.Db.Prepare("SELECT * FROM cookies WHERE content = $1;")
if err != nil {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)
@@ -116,11 +116,11 @@ func (auth *AuthMiddleware) Resolve(next http.HandlerFunc) http.HandlerFunc {
err = row.Scan(&id, &content, &userId, &expiration)
if err != nil {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)
@@ -133,11 +133,11 @@ func (auth *AuthMiddleware) Resolve(next http.HandlerFunc) http.HandlerFunc {
if time.Now().After(expiration) {
cookie = &http.Cookie{
- Name: "paterissa_session_token",
- Value: "",
- Path: "/",
- Domain: os.Getenv("serv"),
- MaxAge: -1,
+ Name: "paterissa_session_token",
+ Value: "",
+ Path: "/",
+ Domain: os.Getenv("serv"),
+ MaxAge: -1,
HttpOnly: true,
}
http.SetCookie(w, cookie)