Files
sonr/pkg/nebula/routes/routes.go
T

73 lines
2.5 KiB
Go
Raw Normal View History

2024-10-07 12:59:08 -04:00
package routes
import (
2024-10-03 17:49:29 -04:00
"bytes"
"github.com/a-h/templ"
"github.com/labstack/echo/v4"
2024-10-07 12:59:08 -04:00
"github.com/onsonr/sonr/pkg/nebula/components/auth"
"github.com/onsonr/sonr/pkg/nebula/components/home"
)
2024-10-06 20:07:24 -04:00
// ╭───────────────────────────────────────────────────────────╮
// │ Marketing Pages │
// ╰───────────────────────────────────────────────────────────╯
func Home(c echo.Context) error {
return render(c, home.View())
}
2024-10-06 20:07:24 -04:00
// ╭───────────────────────────────────────────────────────────╮
// │ Authentication Views │
// ╰───────────────────────────────────────────────────────────╯
2024-10-07 12:59:08 -04:00
func AuthorizeStart(c echo.Context) error {
return render(c, auth.Modal(c))
}
2024-10-07 12:59:08 -04:00
func AuthorizeFinish(c echo.Context) error {
return render(c, auth.Modal(c))
}
func LoginDevice(c echo.Context) error {
return render(c, auth.Modal(c))
}
func LoginStart(c echo.Context) error {
return render(c, auth.Modal(c))
}
func LoginFinish(c echo.Context) error {
return render(c, auth.Modal(c))
}
func RegisterStart(c echo.Context) error {
return render(c, auth.Modal(c))
}
func RegisterFinish(c echo.Context) error {
return render(c, auth.Modal(c))
}
2024-10-03 17:49:29 -04:00
// ╭───────────────────────────────────────────────────────────╮
// │ Helper Methods │
// ╰───────────────────────────────────────────────────────────╯
2024-10-06 20:07:24 -04:00
func render(c echo.Context, cmp templ.Component) error {
2024-10-03 17:49:29 -04:00
// 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
}