Skip to content
This repository was archived by the owner on Oct 10, 2025. It is now read-only.

Commit 8593da8

Browse files
committed
asd
1 parent 45b3724 commit 8593da8

26 files changed

Lines changed: 160 additions & 162 deletions

.golangci.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ linters:
2929
- linters:
3030
- funlen
3131
- ireturn
32+
- goconst
3233
path: _test\.go
3334
- linters:
3435
- lll

go/cmd/email.go

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,26 @@ func getSMS( //nolint:ireturn
111111
return nil, nil //nolint:nilnil // SMS disabled, return nil client
112112
}
113113

114+
provider := strings.ToLower(cCtx.String(flagSMSProvider))
115+
if provider == "" {
116+
provider = "twilio" // Default to Twilio for backward compatibility
117+
}
118+
119+
switch strings.ToLower(cCtx.String(flagSMSProvider)) {
120+
case "twilio":
121+
return getTwilioSMS(cCtx, templates, db)
122+
case "dev":
123+
return sms.NewDev(templates, db, logger), nil
124+
default:
125+
return nil, fmt.Errorf("unsupported SMS provider: %s", provider) //nolint:err113
126+
}
127+
}
128+
129+
func getTwilioSMS( //nolint:ireturn
130+
cCtx *cli.Context,
131+
templates *notifications.Templates,
132+
db *sql.Queries,
133+
) (controller.SMSer, error) {
114134
accountSid := cCtx.String(flagSMSTwilioAccountSid)
115135
authToken := cCtx.String(flagSMSTwilioAuthToken)
116136
messagingServiceID := cCtx.String(flagSMSTwilioMessagingServiceID)
@@ -126,19 +146,8 @@ func getSMS( //nolint:ireturn
126146
), nil
127147
}
128148

129-
if templates == nil {
130-
var err error
131-
132-
templates, err = getTemplates(cCtx, logger)
133-
if err != nil {
134-
return nil, fmt.Errorf("problem creating templates: %w", err)
135-
}
136-
}
137-
138149
return sms.NewTwilioSMS(
139150
templates,
140-
controller.GenerateOTP,
141-
controller.HashOTP,
142151
accountSid,
143152
authToken,
144153
messagingServiceID,

go/cmd/serve.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ const (
9595
flagGoogleAudience = "google-audience"
9696
flagOTPEmailEnabled = "otp-email-enabled"
9797
flagSMSPasswordlessEnabled = "sms-passwordless-enabled"
98+
flagSMSProvider = "sms-provider"
9899
flagSMSTwilioAccountSid = "sms-twilio-account-sid"
99100
flagSMSTwilioAuthToken = "sms-twilio-auth-token" //nolint:gosec
100101
flagSMSTwilioMessagingServiceID = "sms-twilio-messaging-service-id"
@@ -666,6 +667,13 @@ func CommandServe() *cli.Command { //nolint:funlen,maintidx
666667
Category: "sms",
667668
EnvVars: []string{"AUTH_SMS_PASSWORDLESS_ENABLED"},
668669
},
670+
&cli.StringFlag{ //nolint: exhaustruct
671+
Name: flagSMSProvider,
672+
Usage: "SMS provider (twilio or modica)",
673+
Category: "sms",
674+
EnvVars: []string{"AUTH_SMS_PROVIDER"},
675+
Value: "twilio",
676+
},
669677
&cli.StringFlag{ //nolint: exhaustruct
670678
Name: flagSMSTwilioAccountSid,
671679
Usage: "Twilio Account SID for SMS",

go/controller/controller.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,6 @@ type DBClientGetUser interface {
5858
GetUserByEmailAndTicket(
5959
ctx context.Context, arg sql.GetUserByEmailAndTicketParams,
6060
) (sql.AuthUser, error)
61-
GetUserByPhoneNumberAndOTP(
62-
ctx context.Context, arg sql.GetUserByPhoneNumberAndOTPParams,
63-
) (sql.AuthUser, error)
6461
}
6562

6663
type DBClientInsertUser interface {

go/controller/elevate_webauthn_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func TestElevateWebauthn(t *testing.T) {
4646
}
4747
}
4848

49-
credentialIDString := "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec,goconst
49+
credentialIDString := "EuKJAraRGDcmHon-EjDoqoU5Yvk" //nolint:gosec
5050

5151
var credentialID protocol.URLEncodedBase64
5252
if err := credentialID.UnmarshalJSON([]byte(credentialIDString)); err != nil {

go/controller/mock/controller.go

Lines changed: 0 additions & 30 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go/controller/refresh_token_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ func TestRefreshToken(t *testing.T) { //nolint:maintidx
5555

5656
userID := uuid.MustParse("db477732-48fa-4289-b694-2886a646b6eb")
5757
token := uuid.MustParse("1fb17604-86c7-444e-b337-09a644465f2d")
58-
hashedToken := `\x9698157153010b858587119503cbeef0cf288f11775e51cdb6bfd65e930d9310` //nolint:goconst
58+
hashedToken := `\x9698157153010b858587119503cbeef0cf288f11775e51cdb6bfd65e930d9310`
5959
newTokenID := uuid.MustParse("1fb13604-86c7-4444-a337-09a644465f2d")
6060

6161
cases := []testRequest[api.RefreshTokenRequestObject, api.RefreshTokenResponseObject]{

go/controller/secrets.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"golang.org/x/crypto/bcrypt"
99
)
1010

11-
func verifyHashPassword(password, hash string) bool {
11+
func VerifyHashPassword(password, hash string) bool {
1212
err := bcrypt.CompareHashAndPassword([]byte(hash), []byte(password))
1313
return err == nil
1414
}

go/controller/sign_in_email_password.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (ctrl *Controller) SignInEmailPassword( //nolint:ireturn
4141
return ctrl.respondWithError(apiErr), nil
4242
}
4343

44-
if !verifyHashPassword(request.Body.Password, user.PasswordHash.String) {
44+
if !VerifyHashPassword(request.Body.Password, user.PasswordHash.String) {
4545
logger.WarnContext(ctx, "password doesn't match")
4646
return ctrl.sendError(ErrInvalidEmailPassword), nil
4747
}

go/controller/sign_in_otp_email.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,26 @@ package controller
22

33
import (
44
"context"
5+
"crypto/rand"
6+
"fmt"
57
"log/slog"
8+
"math/big"
69
"time"
710

811
"github.com/nhost/hasura-auth/go/api"
912
"github.com/nhost/hasura-auth/go/middleware"
1013
"github.com/nhost/hasura-auth/go/notifications"
1114
)
1215

16+
func generateOTP() (string, error) {
17+
n, err := rand.Int(rand.Reader, big.NewInt(1000000)) //nolint:mnd
18+
if err != nil {
19+
return "", fmt.Errorf("error generating OTP: %w", err)
20+
}
21+
22+
return fmt.Sprintf("%06d", n), nil
23+
}
24+
1325
func (ctrl *Controller) SignInOTPEmail( //nolint:ireturn
1426
ctx context.Context,
1527
request api.SignInOTPEmailRequestObject,
@@ -28,7 +40,7 @@ func (ctrl *Controller) SignInOTPEmail( //nolint:ireturn
2840
return ctrl.respondWithError(apiErr), nil
2941
}
3042

31-
otp, _, err := GenerateOTP()
43+
otp, err := generateOTP()
3244
if err != nil {
3345
logger.ErrorContext(ctx, "error generating OTP", logError(err))
3446
return ctrl.sendError(ErrInternalServerError), nil

0 commit comments

Comments
 (0)