refactor: move session management to dedicated database module

This commit is contained in:
Prad Nukala
2024-12-10 13:40:41 -05:00
parent 518109e9df
commit c67a7823a6
16 changed files with 39 additions and 57 deletions
+4 -4
View File
@@ -2,12 +2,12 @@ package index
import (
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/gateway/session"
"github.com/onsonr/sonr/internal/gateway/context"
)
// Initial users have no authorization, user handle, or vault address
func isInitial(c echo.Context) bool {
sess, err := session.Get(c)
sess, err := context.Get(c)
if err != nil {
return false
}
@@ -17,7 +17,7 @@ func isInitial(c echo.Context) bool {
// Expired users have either a user handle or vault address
func isExpired(c echo.Context) bool {
sess, err := session.Get(c)
sess, err := context.Get(c)
if err != nil {
return false
}
@@ -27,7 +27,7 @@ func isExpired(c echo.Context) bool {
// Returning users have a valid authorization, and either a user handle or vault address
func isReturning(c echo.Context) bool {
sess, err := session.Get(c)
sess, err := context.Get(c)
if err != nil {
return false
}
+3 -3
View File
@@ -6,7 +6,7 @@ import (
"net/http"
"github.com/labstack/echo/v4"
"github.com/onsonr/sonr/internal/gateway/database"
"github.com/onsonr/sonr/internal/database/sessions"
)
type CreateProfileData struct {
@@ -35,8 +35,8 @@ func (d CreateProfileData) IsHumanLabel() string {
return fmt.Sprintf("What is %d + %d?", d.FirstNumber, d.LastNumber)
}
func extractCredentialDescriptor(jsonString string) (*database.Credential, error) {
cred := &database.Credential{}
func extractCredentialDescriptor(jsonString string) (*sessions.Credential, error) {
cred := &sessions.Credential{}
// Unmarshal the credential JSON
if err := json.Unmarshal([]byte(jsonString), cred); err != nil {
return nil, echo.NewHTTPError(http.StatusBadRequest, fmt.Sprintf("invalid credential format: %v", err))