Ensure the auth init is prevented when using nullauth

This commit is contained in:
Melon 2025-01-27 21:38:49 +00:00
parent 2f1f070a5e
commit d48dec6125
Signed by: melon
GPG Key ID: 6C9D970C50D26A25
4 changed files with 18 additions and 12 deletions

12
auth.go Normal file
View File

@ -0,0 +1,12 @@
//go:build !nullauth
package daisy
import (
"github.com/1f349/cardcaldav"
"github.com/charmbracelet/log"
)
func NewAuth(db string, logger *log.Logger) AuthProvider {
return cardcaldav.NewAuth(db, logger)
}

View File

@ -4,9 +4,14 @@ package daisy
import (
"context"
"github.com/charmbracelet/log"
"net/http"
)
func NewAuth(db string, logger *log.Logger) AuthProvider {
return &nullAuth{}
}
type nullAuth struct{}
func (n *nullAuth) Middleware(next http.Handler) http.Handler {
@ -16,7 +21,3 @@ func (n *nullAuth) Middleware(next http.Handler) http.Handler {
func (n *nullAuth) CurrentUserPrincipal(ctx context.Context) (string, error) {
return "/jane@example.com/", nil
}
func NullAuth(_ AuthProvider) AuthProvider {
return &nullAuth{}
}

View File

@ -1,7 +0,0 @@
//go:build !nullauth
package daisy
func NullAuth(provider AuthProvider) AuthProvider {
return provider
}

View File

@ -62,7 +62,7 @@ type AuthProvider interface {
func NewHttpServer(conf Conf, wd string) *http.Server {
cardcaldav.SetupLogger(Logger)
principle := NullAuth(cardcaldav.NewAuth(conf.DB, Logger))
principle := NewAuth(conf.DB, Logger)
_, cardStorage, err := storage.NewFilesystem(filepath.Join(wd, "storage"), "/calendar/", "/contacts/", principle)
if err != nil {