fixed bad import
This commit is contained in:
@@ -1,8 +1,8 @@
|
||||
# hwsauth
|
||||
# HWSAuth
|
||||
|
||||
[](https://pkg.go.dev/git.haelnorr.com/h/golib/hwsauth)
|
||||
|
||||
JWT-based authentication middleware for the [hws](https://git.haelnorr.com/h/golib/hws) web framework.
|
||||
JWT-based authentication middleware for the [HWS](https://git.haelnorr.com/h/golib/hws) web framework.
|
||||
|
||||
## Features
|
||||
|
||||
@@ -65,8 +65,9 @@ func main() {
|
||||
return user, err
|
||||
}
|
||||
|
||||
// Create HWS server
|
||||
server := hws.NewServer(":8080", logger)
|
||||
// Create server
|
||||
serverCfg, _ := hws.ConfigFromEnv()
|
||||
server, _ := hws.NewServer(serverCfg)
|
||||
|
||||
// Create authenticator
|
||||
auth, _ := hwsauth.NewAuthenticator[User, *sql.Tx](
|
||||
@@ -78,17 +79,28 @@ func main() {
|
||||
errorPageFunc,
|
||||
)
|
||||
|
||||
// Define routes
|
||||
routes := []hws.Route{
|
||||
{
|
||||
Path: "/dashboard",
|
||||
Method: hws.MethodGET,
|
||||
Handler: auth.LoginReq(http.HandlerFunc(dashboardHandler)),
|
||||
},
|
||||
}
|
||||
|
||||
server.AddRoutes(routes...)
|
||||
|
||||
// Add authentication middleware
|
||||
server.AddMiddleware(auth.Authenticate())
|
||||
|
||||
// Optionally ignore public paths
|
||||
auth.IgnorePaths("/", "/login", "/register", "/static")
|
||||
|
||||
// Protect routes
|
||||
protectedHandler := auth.LoginReq(http.HandlerFunc(dashboardHandler))
|
||||
server.AddRoute("GET", "/dashboard", protectedHandler)
|
||||
|
||||
server.Start()
|
||||
// Start server
|
||||
ctx := context.Background()
|
||||
server.Start(ctx)
|
||||
|
||||
<-server.Ready()
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
Reference in New Issue
Block a user