Skip to content

Commit

Permalink
fix: remove email from required fields as some users may not have one (
Browse files Browse the repository at this point in the history
…#529)

Fixes #526
  • Loading branch information
dbarrosop authored Jun 13, 2024
1 parent 067dd7b commit 05ab45b
Show file tree
Hide file tree
Showing 12 changed files with 79 additions and 129 deletions.
1 change: 0 additions & 1 deletion go/api/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,6 @@ components:
- createdAt
- defaultRole
- displayName
- email
- emailVerified
- id
- isAnonymous
Expand Down
52 changes: 26 additions & 26 deletions go/api/server.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions go/api/types.gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions go/controller/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package controller_test

import (
"context"
"encoding/json"
"net/url"
"strings"
"testing"
Expand Down Expand Up @@ -245,6 +246,10 @@ func assertRequest[T any, U any](
cmpopts.IgnoreFields(api.Session{}, "RefreshToken", "AccessToken"), //nolint:exhaustruct
}, options...)

if _, err := json.Marshal(resp); err != nil {
t.Fatalf("failed to marshal response: %v", err)
}

if diff := cmp.Diff(
resp, expectedResponse,
cmpopts...,
Expand Down
8 changes: 4 additions & 4 deletions go/controller/post_signin_email_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ import (
"github.com/nhost/hasura-auth/go/controller"
"github.com/nhost/hasura-auth/go/controller/mock"
"github.com/nhost/hasura-auth/go/sql"
"github.com/oapi-codegen/runtime/types"
"go.uber.org/mock/gomock"
)

//nolint:dupl
func getSigninUser(userID uuid.UUID) sql.AuthUser {
//nolint:exhaustruct
return sql.AuthUser{
Expand Down Expand Up @@ -115,7 +115,7 @@ func TestPostSigninEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: true,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestPostSigninEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: true,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -445,7 +445,7 @@ func TestPostSigninEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down
5 changes: 3 additions & 2 deletions go/controller/post_signin_pat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"github.com/nhost/hasura-auth/go/controller"
"github.com/nhost/hasura-auth/go/controller/mock"
"github.com/nhost/hasura-auth/go/sql"
"github.com/oapi-codegen/runtime/types"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -81,7 +82,7 @@ func TestPostSigninPat(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: true,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestPostSigninPat(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: true,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down
11 changes: 6 additions & 5 deletions go/controller/post_signup_email_password_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/nhost/hasura-auth/go/notifications"
"github.com/nhost/hasura-auth/go/sql"
"github.com/nhost/hasura-auth/go/testhelpers"
"github.com/oapi-codegen/runtime/types"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -86,7 +87,7 @@ func TestPostSignupEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "[email protected]",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -188,7 +189,7 @@ func TestPostSignupEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "me",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -643,7 +644,7 @@ func TestPostSignupEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "[email protected]",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -779,7 +780,7 @@ func TestPostSignupEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "[email protected]",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -874,7 +875,7 @@ func TestPostSignupEmailPassword(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "[email protected]",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down
5 changes: 3 additions & 2 deletions go/controller/post_signup_webauthn_verify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
"github.com/nhost/hasura-auth/go/notifications"
"github.com/nhost/hasura-auth/go/sql"
"github.com/nhost/hasura-auth/go/testhelpers"
"github.com/oapi-codegen/runtime/types"
"go.uber.org/mock/gomock"
)

Expand Down Expand Up @@ -223,7 +224,7 @@ func TestPostSignupWebauthnVerify(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "cf91d1bc-875e-49bc-897f-fbccf32ede11",
IsAnonymous: false,
Expand Down Expand Up @@ -319,7 +320,7 @@ func TestPostSignupWebauthnVerify(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: false,
Id: "cf91d1bc-875e-49bc-897f-fbccf32ede11",
IsAnonymous: false,
Expand Down
10 changes: 5 additions & 5 deletions go/controller/post_token_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import (
"github.com/nhost/hasura-auth/go/controller"
"github.com/nhost/hasura-auth/go/controller/mock"
"github.com/nhost/hasura-auth/go/sql"
"github.com/oapi-codegen/runtime/types"
"go.uber.org/mock/gomock"
)

//nolint:dupl
func getAnonymousUser(userID uuid.UUID) sql.AuthUser {
//nolint:exhaustruct
return sql.AuthUser{
Expand All @@ -31,9 +31,9 @@ func getAnonymousUser(userID uuid.UUID) sql.AuthUser {
DisplayName: "Anonymous User",
AvatarUrl: "",
Locale: "en",
Email: sql.Text(""),
Email: pgtype.Text{},
PhoneNumber: pgtype.Text{},
PasswordHash: sql.Text(""),
PasswordHash: pgtype.Text{},
EmailVerified: false,
PhoneNumberVerified: false,
NewEmail: pgtype.Text{},
Expand Down Expand Up @@ -105,7 +105,7 @@ func TestPostToken(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "user",
DisplayName: "Jane Doe",
Email: "[email protected]",
Email: ptr(types.Email("[email protected]")),
EmailVerified: true,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: false,
Expand Down Expand Up @@ -188,7 +188,7 @@ func TestPostToken(t *testing.T) { //nolint:maintidx
CreatedAt: time.Now(),
DefaultRole: "anonymous",
DisplayName: "Anonymous User",
Email: "",
Email: nil,
EmailVerified: false,
Id: "db477732-48fa-4289-b694-2886a646b6eb",
IsAnonymous: true,
Expand Down
18 changes: 13 additions & 5 deletions go/controller/workflows.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,14 @@ func (wf *Workflows) GetUserByRefreshTokenHash(
return user, nil
}

func pgtypeTextToOAPIEmail(pgemail pgtype.Text) *types.Email {
var email *types.Email
if pgemail.Valid {
email = ptr(types.Email(pgemail.String))
}
return email
}

func (wf *Workflows) UpdateSession( //nolint:funlen
ctx context.Context,
user sql.AuthUser,
Expand Down Expand Up @@ -350,7 +358,7 @@ func (wf *Workflows) UpdateSession( //nolint:funlen
CreatedAt: user.CreatedAt.Time,
DefaultRole: user.DefaultRole,
DisplayName: user.DisplayName,
Email: types.Email(user.Email.String),
Email: pgtypeTextToOAPIEmail(user.Email),
EmailVerified: user.EmailVerified,
Id: user.ID.String(),
IsAnonymous: user.IsAnonymous,
Expand Down Expand Up @@ -413,7 +421,7 @@ func (wf *Workflows) NewSession(
CreatedAt: user.CreatedAt.Time,
DefaultRole: user.DefaultRole,
DisplayName: user.DisplayName,
Email: types.Email(user.Email.String),
Email: pgtypeTextToOAPIEmail(user.Email),
EmailVerified: user.EmailVerified,
Id: user.ID.String(),
IsAnonymous: false,
Expand Down Expand Up @@ -729,7 +737,7 @@ func (wf *Workflows) SignupUserWithRefreshToken( //nolint:funlen
CreatedAt: time.Now(),
DefaultRole: *options.DefaultRole,
DisplayName: deptr(options.DisplayName),
Email: types.Email(email),
Email: ptr(types.Email(email)),
EmailVerified: false,
Id: resp.UserID.String(),
IsAnonymous: false,
Expand Down Expand Up @@ -862,7 +870,7 @@ func (wf *Workflows) SignupUserWithSecurityKeyAndRefreshToken( //nolint:funlen
CreatedAt: time.Now(),
DefaultRole: *options.DefaultRole,
DisplayName: deptr(options.DisplayName),
Email: types.Email(email),
Email: ptr(types.Email(email)),
EmailVerified: false,
Id: userID.String(),
IsAnonymous: false,
Expand Down Expand Up @@ -931,7 +939,7 @@ func (wf *Workflows) SignupUserWithSecurityKey( //nolint:funlen
CreatedAt: time.Now(),
DefaultRole: *options.DefaultRole,
DisplayName: deptr(options.DisplayName),
Email: types.Email(email),
Email: ptr(types.Email(email)),
EmailVerified: false,
Id: userID.String(),
IsAnonymous: false,
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,8 @@
"follow-redirects@<=1.15.5": ">=1.15.6",
"express@<4.19.2": ">=4.19.2",
"execa@<=0.10.0": ">=2.0.0",
"pug@<=3.0.2": ">=3.0.3"
"pug@<=3.0.2": ">=3.0.3",
"braces@<3.0.3": ">=3.0.3"
}
}
}
Loading

0 comments on commit 05ab45b

Please sign in to comment.