Skip to content

Commit

Permalink
feat: change type and add parameter guard for language in magic link …
Browse files Browse the repository at this point in the history
…options
  • Loading branch information
ctran88 committed Jan 8, 2025
1 parent c5693f5 commit 4d019a5
Showing 1 changed file with 21 additions and 1 deletion.
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
}
}

return fmt.Errorf("Language must be one of %v", validLanguages)
}

0 comments on commit 4d019a5

Please sign in to comment.