Skip to content
This repository was archived by the owner on Jan 16, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
)

type MagicLinkOptions struct {
Language string
Language MagicLinkLanguage
MagicLinkPath string
RedirectURL string
TTL int
Expand Down Expand Up @@ -125,6 +125,10 @@ func (a *auth) ValidateJWT(jwt string) (string, error) {

func (a *auth) createMagicLink(args magicLinkArgs, opts *MagicLinkOptions) (*MagicLink, error) {
if opts != nil {
if err := validateLanguage(opts.Language); err != nil {
return nil, err
}

args.Language = opts.Language
args.MagicLinkPath = opts.MagicLinkPath
args.RedirectURL = opts.RedirectURL
Expand Down Expand Up @@ -159,3 +163,19 @@ func (a *auth) getPublicKey(token *jwt.Token) (interface{}, error) {

return pubKey, err
}

func validateLanguage(language MagicLinkLanguage) error {
if language == "" {
return nil
}

validLanguages := []MagicLinkLanguage{De, En, Es, It, Pl, Pt, Zh}

for _, l := range validLanguages {
if l == language {
return nil
}
}
Comment on lines +172 to +176

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that the SDK is using Go 1.21, the slices package is available (release note), so this could be simplified to:

import "slices"

validLanguages := []MagicLinkLanguage{De, En, Es, It, Pl, Pt, Zh}

if slices.Contains(validLanguages, language) {
    return nil
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 630b223


return fmt.Errorf("Language must be one of %v", validLanguages)
}
16 changes: 5 additions & 11 deletions overlay.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,6 @@ actions:
- EmailChannel
- PhoneChannel

- target: $.components.schemas.UserMetadataFieldType
description: Rename the generated Go enum name
update:
x-enumNames:
- StringMD
- BooleanMD
- IntegerMD
- DateMD
- PhoneMD
- EmailMD

- target: $.components.schemas.UserEventAction
description: Rename the generated Go enum name
update:
Expand Down Expand Up @@ -111,6 +100,11 @@ actions:
update:
x-go-type-skip-optional-pointer: true

- target: $.components.schemas.MagicLinkLanguage
description: Don't use pointers for optional properties in the generated Go type
update:
x-go-type-skip-optional-pointer: true

- target: $.components.schemas.UserInfo.properties.user_metadata
description: Don't use pointers for optional properties in the generated Go type
update:
Expand Down
Loading