Skip to content

Commit 2d00814

Browse files
committed
add feature to create email action link of verify and change email
1 parent 77177c7 commit 2d00814

File tree

1 file changed

+29
-7
lines changed

1 file changed

+29
-7
lines changed

auth/email_action_links.go

Lines changed: 29 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,10 @@ func (settings *ActionCodeSettings) toMap() (map[string]interface{}, error) {
6464
type linkType string
6565

6666
const (
67-
emailLinkSignIn linkType = "EMAIL_SIGNIN"
68-
emailVerification linkType = "VERIFY_EMAIL"
69-
passwordReset linkType = "PASSWORD_RESET"
67+
emailLinkSignIn linkType = "EMAIL_SIGNIN"
68+
emailVerification linkType = "VERIFY_EMAIL"
69+
passwordReset linkType = "PASSWORD_RESET"
70+
verifyAndChangeEmail linkType = "VERIFY_AND_CHANGE_EMAIL"
7071
)
7172

7273
// EmailVerificationLink generates the out-of-band email action link for email verification flows for the specified
@@ -79,7 +80,7 @@ func (c *baseClient) EmailVerificationLink(ctx context.Context, email string) (s
7980
// specified email address, using the action code settings provided.
8081
func (c *baseClient) EmailVerificationLinkWithSettings(
8182
ctx context.Context, email string, settings *ActionCodeSettings) (string, error) {
82-
return c.generateEmailActionLink(ctx, emailVerification, email, settings)
83+
return c.generateEmailActionLink(ctx, emailVerification, email, settings, nil)
8384
}
8485

8586
// PasswordResetLink generates the out-of-band email action link for password reset flows for the specified email
@@ -92,18 +93,31 @@ func (c *baseClient) PasswordResetLink(ctx context.Context, email string) (strin
9293
// specified email address, using the action code settings provided.
9394
func (c *baseClient) PasswordResetLinkWithSettings(
9495
ctx context.Context, email string, settings *ActionCodeSettings) (string, error) {
95-
return c.generateEmailActionLink(ctx, passwordReset, email, settings)
96+
return c.generateEmailActionLink(ctx, passwordReset, email, settings, nil)
9697
}
9798

9899
// EmailSignInLink generates the out-of-band email action link for email link sign-in flows, using the action
99100
// code settings provided.
100101
func (c *baseClient) EmailSignInLink(
101102
ctx context.Context, email string, settings *ActionCodeSettings) (string, error) {
102-
return c.generateEmailActionLink(ctx, emailLinkSignIn, email, settings)
103+
return c.generateEmailActionLink(ctx, emailLinkSignIn, email, settings, nil)
104+
}
105+
106+
// VerifyAndChangeEmailLink generates the out-of-band email action link for email verification and change flows for the
107+
// specified email address.
108+
func (c *baseClient) VerifyAndChangeEmailLink(ctx context.Context, email string, newEmail string) (string, error) {
109+
return c.VerifyAndChangeEmailLinkWithSettings(ctx, email, newEmail, nil)
110+
}
111+
112+
// VerifyAndChangeEmailLinkWithSettings generates the out-of-band email action link for email verification and change
113+
// flows for the specified email address, using the action code settings provided.
114+
func (c *baseClient) VerifyAndChangeEmailLinkWithSettings(
115+
ctx context.Context, email string, newEmail string, settings *ActionCodeSettings) (string, error) {
116+
return c.generateEmailActionLink(ctx, verifyAndChangeEmail, email, settings, &newEmail)
103117
}
104118

105119
func (c *baseClient) generateEmailActionLink(
106-
ctx context.Context, linkType linkType, email string, settings *ActionCodeSettings) (string, error) {
120+
ctx context.Context, linkType linkType, email string, settings *ActionCodeSettings, newEmail *string) (string, error) {
107121

108122
if email == "" {
109123
return "", errors.New("email must not be empty")
@@ -118,6 +132,14 @@ func (c *baseClient) generateEmailActionLink(
118132
"email": email,
119133
"returnOobLink": true,
120134
}
135+
136+
if linkType == verifyAndChangeEmail {
137+
if newEmail == nil {
138+
return "", errors.New("newEmail must not be nil when linkType is verifyAndChangeEmail")
139+
}
140+
payload["newEmail"] = *newEmail
141+
}
142+
121143
if settings != nil {
122144
settingsMap, err := settings.toMap()
123145
if err != nil {

0 commit comments

Comments
 (0)