added logout

This commit is contained in:
2026-01-24 15:23:28 +11:00
parent 73a5c9726b
commit 4dec97def8
14 changed files with 327 additions and 191 deletions

View File

@@ -48,13 +48,13 @@ func addRoutes(
},
{
Path: "/register",
Method: hws.MethodGET,
Methods: []hws.Method{hws.MethodGET, hws.MethodPOST},
Handler: auth.LogoutReq(handlers.Register(server, auth, conn, cfg, store)),
},
{
Path: "/register",
Method: hws.MethodPOST,
Handler: auth.LogoutReq(handlers.Register(server, auth, conn, cfg, store)),
Path: "/logout",
Methods: []hws.Method{hws.MethodGET, hws.MethodPOST},
Handler: auth.LoginReq(handlers.Logout(server, auth, conn, discordAPI)),
},
}

View File

@@ -18,12 +18,12 @@ import (
)
// Initializes and runs the server
func run(ctx context.Context, w io.Writer, config *config.Config) error {
func run(ctx context.Context, w io.Writer, cfg *config.Config) error {
ctx, cancel := signal.NotifyContext(ctx, os.Interrupt)
defer cancel()
// Setup the logger
logger, err := hlog.NewLogger(config.HLOG, w)
logger, err := hlog.NewLogger(cfg.HLOG, w)
if err != nil {
return errors.Wrap(err, "hlog.NewLogger")
}
@@ -31,7 +31,7 @@ func run(ctx context.Context, w io.Writer, config *config.Config) error {
// Setup the database connection
logger.Debug().Msg("Config loaded and logger started")
logger.Debug().Msg("Connecting to database")
bun, closedb, err := setupBun(ctx, config)
bun, closedb, err := setupBun(ctx, cfg)
if err != nil {
return errors.Wrap(err, "setupDBConn")
}
@@ -50,10 +50,13 @@ func run(ctx context.Context, w io.Writer, config *config.Config) error {
// Setup Discord API client
logger.Debug().Msg("Setting up Discord API client")
discordAPI := discord.NewRateLimitedClient(logger)
discordAPI, err := discord.NewAPIClient(cfg.Discord, logger, cfg.HWSAuth.TrustedHost)
if err != nil {
return errors.Wrap(err, "discord.NewAPIClient")
}
logger.Debug().Msg("Setting up HTTP server")
httpServer, err := setupHttpServer(&staticFS, config, logger, bun, store, discordAPI)
httpServer, err := setupHttpServer(&staticFS, cfg, logger, bun, store, discordAPI)
if err != nil {
return errors.Wrap(err, "setupHttpServer")
}