Datastar's NewSSE() flushes HTTP headers before SCS's session middleware can attach the Set-Cookie header, so the session cookie never reaches the browser after login/register/logout. Convert login, register, and logout to standard HTML forms with HTTP redirects, which lets SCS write cookies normally. Also fix return_url capture on the login page (was never being stored in the session). Add handler tests covering login, register, and logout flows.
17 lines
521 B
Go
17 lines
521 B
Go
// Package auth handles user authentication routes and handlers.
|
|
package auth
|
|
|
|
import (
|
|
"github.com/alexedwards/scs/v2"
|
|
"github.com/go-chi/chi/v5"
|
|
|
|
"github.com/ryanhamamura/games/db/repository"
|
|
)
|
|
|
|
func SetupRoutes(router chi.Router, queries *repository.Queries, sessions *scs.SessionManager) {
|
|
router.Get("/login", HandleLoginPage(sessions))
|
|
router.Get("/register", HandleRegisterPage())
|
|
router.Post("/auth/login", HandleLogin(queries, sessions))
|
|
router.Post("/auth/register", HandleRegister(queries, sessions))
|
|
}
|