From 7cbc9e0bb10ae7247781913b11f8b719ddee6746 Mon Sep 17 00:00:00 2001 From: Prad Nukala Date: Wed, 23 Oct 2024 09:52:07 -0400 Subject: [PATCH] feat: implement authentication register finish endpoint --- .../components/authentication/modal.templ | 3 +++ pkg/nebula/components/authentication/route.go | 4 +++ .../components/authentication/view.templ | 26 +++++++++---------- pkg/workers/handlers/auth.go | 18 +++++++------ 4 files changed, 30 insertions(+), 21 deletions(-) diff --git a/pkg/nebula/components/authentication/modal.templ b/pkg/nebula/components/authentication/modal.templ index b5e39eb8a..1970264f5 100644 --- a/pkg/nebula/components/authentication/modal.templ +++ b/pkg/nebula/components/authentication/modal.templ @@ -6,18 +6,21 @@ import ( "github.com/onsonr/sonr/pkg/nebula/global/styles" ) +// RegisterModal returns the Register Modal. templ RegisterModal(c echo.Context) { @styles.OpenModal("Account Registration", "Enter your account information below to create your account.") { @sections.RegisterStart() } } +// LoginModal returns the Login Modal. templ LoginModal(c echo.Context) { @styles.OpenModal("Account Registration", "Enter your account information below to create your account.") { @sections.LoginStart() } } +// AuthorizeModal returns the Authorize Modal. templ AuthorizeModal(c echo.Context) { @styles.OpenModal("Account Registration", "Enter your account information below to create your account.") { @sections.AuthorizeStart() diff --git a/pkg/nebula/components/authentication/route.go b/pkg/nebula/components/authentication/route.go index 2e85d2de1..42b18a7c0 100644 --- a/pkg/nebula/components/authentication/route.go +++ b/pkg/nebula/components/authentication/route.go @@ -11,6 +11,7 @@ import ( // │ DWN Routes - Authentication │ // ╰───────────────────────────────────────────────────────────╯ +// CurrentViewRoute returns the current view route. func CurrentViewRoute(c echo.Context) error { s, err := ctx.GetDWNContext(c) if err != nil { @@ -24,14 +25,17 @@ func CurrentViewRoute(c echo.Context) error { // │ Hway Routes - Authentication │ // ╰───────────────────────────────────────────────────────────╯ +// AuthorizeModalRoute returns the Authorize Modal route. func AuthorizeModalRoute(c echo.Context) error { return ctx.RenderTempl(c, AuthorizeModal(c)) } +// LoginModalRoute returns the Login Modal route. func LoginModalRoute(c echo.Context) error { return ctx.RenderTempl(c, LoginModal(c)) } +// RegisterModalRoute returns the Register Modal route. func RegisterModalRoute(c echo.Context) error { return ctx.RenderTempl(c, RegisterModal(c)) } diff --git a/pkg/nebula/components/authentication/view.templ b/pkg/nebula/components/authentication/view.templ index bb631cd74..8a646b65c 100644 --- a/pkg/nebula/components/authentication/view.templ +++ b/pkg/nebula/components/authentication/view.templ @@ -2,22 +2,22 @@ package authentication import echo "github.com/labstack/echo/v4" +// CurrentView checks if the user is logged in. templ CurrentView(c echo.Context) { -
-
-
-
-
-

Current Account

-
-
-

- Logout -

+
+
+
+
+
+

Current Account

+
+
+

+ Logout +

+
-
} - diff --git a/pkg/workers/handlers/auth.go b/pkg/workers/handlers/auth.go index 23f0ac854..6b3ee13ed 100644 --- a/pkg/workers/handlers/auth.go +++ b/pkg/workers/handlers/auth.go @@ -7,14 +7,20 @@ import ( "github.com/onsonr/sonr/internal/orm" ) +type authAPI struct{} + +var Auth = new(authAPI) + // ╭───────────────────────────────────────────────────────────╮ // │ Login Handlers │ // ╰───────────────────────────────────────────────────────────╯ +// LoginSubjectCheck handles the login subject check. func (a *authAPI) LoginSubjectCheck(e echo.Context) error { return e.JSON(200, "HandleCredentialAssertion") } +// LoginSubjectStart handles the login subject start. func (a *authAPI) LoginSubjectStart(e echo.Context) error { opts := &protocol.PublicKeyCredentialRequestOptions{ UserVerification: "preferred", @@ -23,6 +29,7 @@ func (a *authAPI) LoginSubjectStart(e echo.Context) error { return e.JSON(200, opts) } +// LoginSubjectFinish handles the login subject finish. func (a *authAPI) LoginSubjectFinish(e echo.Context) error { var crr protocol.CredentialAssertionResponse if err := e.Bind(&crr); err != nil { @@ -35,11 +42,13 @@ func (a *authAPI) LoginSubjectFinish(e echo.Context) error { // │ Register Handlers │ // ╰───────────────────────────────────────────────────────────╯ +// RegisterSubjectCheck handles the register subject check. func (a *authAPI) RegisterSubjectCheck(e echo.Context) error { subject := e.FormValue("subject") return e.JSON(200, subject) } +// RegisterSubjectStart handles the register subject start. func (a *authAPI) RegisterSubjectStart(e echo.Context) error { // Get subject and address subject := e.FormValue("subject") @@ -53,6 +62,7 @@ func (a *authAPI) RegisterSubjectStart(e echo.Context) error { return e.JSON(201, orm.NewCredentialCreationOptions(subject, address, chal)) } +// RegisterSubjectFinish handles the register subject finish. func (a *authAPI) RegisterSubjectFinish(e echo.Context) error { // Deserialize the JSON into a temporary struct var ccr protocol.CredentialCreationResponse @@ -70,11 +80,3 @@ func (a *authAPI) RegisterSubjectFinish(e echo.Context) error { // // credential := orm.NewCredential(parsedData, e.Request().Host, "") return e.JSON(201, ccr) } - -// ╭───────────────────────────────────────────────────────────╮ -// │ Group Structures │ -// ╰───────────────────────────────────────────────────────────╯ - -type authAPI struct{} - -var Auth = new(authAPI)