DEVELOPMENT ENVIRONMENT

~liljamo/felu

62e1b4ec72bb9bab9b588792f172631deb78e38a — Jonni Liljamo 1 year, 1 month ago 2181245 0.1.0
feat: logout
M internal/components/base.templ => internal/components/base.templ +1 -0
@@ 46,6 46,7 @@ templ ManageBase(title string) {
			<div class="flex w-full max-w-5xl items-center gap-4">
				<a href="/manage">{ serviceName() }</a>
				<a class="border p-1" href="/manage/user">User Settings</a>
				<button class="border p-1" hx-get="/auth/logout">Logout</button>
			</div>
			<div class="flex flex-col w-full max-w-5xl items-center gap-2">
				{ children... }

M internal/components/base_templ.go => internal/components/base_templ.go +10 -1
@@ 167,7 167,16 @@ func ManageBase(title string) templ.Component {
			if err != nil {
				return err
			}
			_, err = templBuffer.WriteString("</a></div><div class=\"flex flex-col w-full max-w-5xl items-center gap-2\">")
			_, err = templBuffer.WriteString("</a><button class=\"border p-1\" hx-get=\"/auth/logout\">")
			if err != nil {
				return err
			}
			var_12 := `Logout`
			_, err = templBuffer.WriteString(var_12)
			if err != nil {
				return err
			}
			_, err = templBuffer.WriteString("</button></div><div class=\"flex flex-col w-full max-w-5xl items-center gap-2\">")
			if err != nil {
				return err
			}

M internal/handlers/auth.go => internal/handlers/auth.go +7 -0
@@ 40,3 40,10 @@ func AuthLogin(sm *scs.SessionManager) gin.HandlerFunc {
		c.Header("HX-Redirect", "/manage")
	}
}

func AuthLogout(sm *scs.SessionManager) gin.HandlerFunc {
	return func(c *gin.Context) {
		sm.Destroy(c.Request.Context())
		c.Header("HX-Refresh", "true")
	}
}

M internal/routers/frontend.go => internal/routers/frontend.go +1 -0
@@ 30,6 30,7 @@ func SetupFrontendRouter(sm *scs.SessionManager) *gin.Engine {
	auth := r.Group("/auth")
	{
		auth.POST("/login", handlers.AuthLogin(sm))
		auth.GET("/logout", handlers.AuthLogout(sm))
	}

	// routes for the actual application frontend