Files
sonr/internal/vault/handlers/index/handlers.go
T

49 lines
1.7 KiB
Go
Raw Normal View History

2024-12-05 20:36:58 -05:00
package handlers
import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/vault/context"
2024-12-05 20:36:58 -05:00
)
func Handler(c echo.Context) error {
// TODO: Create views
2024-12-05 20:36:58 -05:00
if isInitial(c) {
// return response.TemplEcho(c, index.InitialView())
2024-12-05 20:36:58 -05:00
}
// TODO: Add authorization check
2024-12-05 20:36:58 -05:00
if isExpired(c) {
// return response.TemplEcho(c, index.ReturningView())
2024-12-05 20:36:58 -05:00
}
return c.Render(http.StatusOK, "index.templ", nil)
}
// ╭─────────────────────────────────────────────────────────╮
// │ Utility Functions │
// ╰─────────────────────────────────────────────────────────╯
// Initial users have no authorization, user handle, or vault address
func isInitial(c echo.Context) bool {
noAuth := !context.HasAuthorization(c)
noUserHandle := !context.HasUserHandle(c)
noVaultAddress := !context.HasVaultAddress(c)
2024-12-05 20:36:58 -05:00
return noUserHandle && noVaultAddress && noAuth
}
// Expired users have either a user handle or vault address
func isExpired(c echo.Context) bool {
noAuth := !context.HasAuthorization(c)
hasUserHandle := context.HasUserHandle(c)
hasVaultAddress := context.HasVaultAddress(c)
2024-12-05 20:36:58 -05:00
return noAuth && hasUserHandle || noAuth && hasVaultAddress
}
// Returning users have a valid authorization, and either a user handle or vault address
func isReturning(c echo.Context) bool {
hasAuth := context.HasAuthorization(c)
hasUserHandle := context.HasUserHandle(c)
hasVaultAddress := context.HasVaultAddress(c)
2024-12-05 20:36:58 -05:00
return hasAuth && (hasUserHandle || hasVaultAddress)
}