Skip to content

Commit

Permalink
bugfix signup (#40)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielbonilha authored Oct 27, 2022
1 parent 978ffe4 commit 996cc43
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 26 deletions.
22 changes: 16 additions & 6 deletions gateway/security/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ type (

UserService interface {
FindBySub(sub string) (*user.Context, error)
GetOrgByName(name string) (*user.Org, error)
Persist(u any) error
}

Expand Down Expand Up @@ -148,16 +149,25 @@ func (s *Service) signup(context *user.Context, sub string, profile map[string]a
org = user.ExtractDomain(email)
}

context.Org = &user.Org{
Id: uuid.NewString(),
Name: org,
orgData, err := s.UserService.GetOrgByName(org)
if err != nil {
return err
}

if err := s.UserService.Persist(context.Org); err != nil {
return err
if orgData == nil {
orgData = &user.Org{
Id: uuid.NewString(),
Name: org,
}

if err := s.UserService.Persist(orgData); err != nil {
return err
}

newOrg = true
}

newOrg = true
context.Org = orgData
}

if context.User == nil {
Expand Down
23 changes: 4 additions & 19 deletions gateway/user/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,11 @@ func (s *Service) Signup(org *Org, user *User) (txId int64, err error) {
}

func (s *Service) FindBySub(sub string) (*Context, error) {
context, err := s.Storage.FindById(sub)
if err != nil {
return nil, err
}

if context.User == nil {
return context, nil
}

orgName := ExtractDomain(context.User.Email)

if context.Org == nil {
org, err := s.Storage.GetOrgByName(orgName)
if err != nil {
return nil, err
}
context.Org = org
}
return s.Storage.FindById(sub)
}

return context, nil
func (s *Service) GetOrgByName(name string) (*Org, error) {
return s.Storage.GetOrgByName(name)
}

func (s *Service) Persist(user any) error {
Expand Down
2 changes: 1 addition & 1 deletion gateway/user/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ func (s *Storage) GetOrgByName(name string) (*Org, error) {
var payload = `{:query {
:find [(pull ?org [*])]
:in [name]
:where [[?user :org/name name]]}
:where [[?org :org/name name]]}
:in-args ["` + name + `"]}`

b, err := s.Query([]byte(payload))
Expand Down

0 comments on commit 996cc43

Please sign in to comment.