MCPcopy Create free account
hub / github.com/dnote/dnote / GuestOnly

Function GuestOnly

pkg/server/middleware/auth.go:161–175  ·  view source on GitHub ↗
(db *gorm.DB, next http.HandlerFunc)

Source from the content-addressed store, hash-verified

159}
160
161func GuestOnly(db *gorm.DB, next http.HandlerFunc) http.HandlerFunc {
162 return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
163 _, ok, err := AuthWithSession(db, r)
164 if err != nil {
165 // log the error and continue
166 log.ErrorWrap(err, "authenticating with session")
167 }
168
169 if ok {
170 http.Redirect(w, r, "/", http.StatusFound)
171 } else {
172 next.ServeHTTP(w, r)
173 }
174 })
175}

Callers 1

TestGuestOnlyFunction · 0.85

Calls 3

ErrorWrapFunction · 0.92
AuthWithSessionFunction · 0.85
ServeHTTPMethod · 0.80

Tested by 1

TestGuestOnlyFunction · 0.68