Files
sonr/pkg/nebula/router/router.go
T
Prad NukalaandGitHub d93c19c2ab feature/1107 integrate dexie db (#1128)
- **feat: remove grant page**
- **refactor: remove alert, input, radios, tabs, and video blocks**
- **feat: add JSON serialization to DWN config**
- **feat: add new Highway gateway component**
- **refactor: remove unused chains.yaml and devbox.json**
- **refactor: Separate request and response headers into protected and
non-protected structs**
- **feat: Update the UseSession echo middleware to bind the correct
headers and provide methods for updating HTMX context from Go**
- **refactor: remove unused headers from session**
- **feat: add authorize endpoint**
- **feat: create marketing pages**
2024-10-06 20:07:24 -04:00

68 lines
2.6 KiB
Go

package router
import (
"bytes"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/pkg/nebula/components/grant"
"github.com/onsonr/sonr/pkg/nebula/components/home"
"github.com/onsonr/sonr/pkg/nebula/components/login"
"github.com/onsonr/sonr/pkg/nebula/components/profile"
"github.com/onsonr/sonr/pkg/nebula/components/register"
"github.com/onsonr/sonr/pkg/nebula/models"
)
// ╭───────────────────────────────────────────────────────────╮
// │ Marketing Pages │
// ╰───────────────────────────────────────────────────────────╯
func Home(c echo.Context) error {
mdls, err := models.GetModels()
if err != nil {
return err
}
return render(c, home.View(mdls.Home))
}
func Profile(c echo.Context) error {
return render(c, profile.View(c))
}
// ╭───────────────────────────────────────────────────────────╮
// │ Authentication Views │
// ╰───────────────────────────────────────────────────────────╯
func Authorize(c echo.Context) error {
return render(c, grant.View(c))
}
func Login(c echo.Context) error {
return render(c, login.Modal(c))
}
func Register(c echo.Context) error {
return render(c, register.Modal(c))
}
// ╭───────────────────────────────────────────────────────────╮
// │ Helper Methods │
// ╰───────────────────────────────────────────────────────────╯
func render(c echo.Context, cmp templ.Component) error {
// Create a buffer to store the rendered HTML
buf := &bytes.Buffer{}
// Render the component to the buffer
err := cmp.Render(c.Request().Context(), buf)
if err != nil {
return err
}
// Set the content type
c.Response().Header().Set(echo.HeaderContentType, echo.MIMETextHTML)
// Write the buffered content to the response
_, err = c.Response().Write(buf.Bytes())
return err
}