Skip to content

Feat: Generate email action links#133

Merged
awalias merged 6 commits into
masterfrom
feat/generate-email-links
Jul 14, 2021
Merged

Feat: Generate email action links#133
awalias merged 6 commits into
masterfrom
feat/generate-email-links

Conversation

@kangmingtay
Copy link
Copy Markdown
Member

@kangmingtay kangmingtay commented Jul 7, 2021

What kind of change does this PR introduce?

Allows an admin user to generate email action links (signup, magiclink, recovery, invite).

What is the current behavior?

Admin user cannot make use of their own custom email service (e.g. Sendgrid) or email templates to serve their customers.
#109

What is the new behavior?

Adds a new admin endpoint: POST /admin/generate_link?type=TYPE&redirect_to=REDIRECT_URL
Allows an admin user to generate the corresponding email action link to send in their custom email templates.

Additional context

Requires admin credentials because the email action links contain the verification token used to sign a user in.

Sign up a new user via magiclink
Request:

POST /admin/generate_link?type=magiclink&redirect_to=REDIRECT_URL

Response:

{
    "action_link": "http://localhost:9999/verify?token=TOKEN&type=signup&redirect_to=REDIRECT_URL",
    "app_metadata": {
        "provider": "email"
    },
    "aud": "authenticated",
    "confirmation_sent_at": "2021-07-07T18:40:29.314439+08:00",
    "created_at": "2021-07-07T18:40:31.144371+08:00",
    "email": "newuser@mail.com",
    "id": "user_id",
    "role": "authenticated",
    "updated_at": "2021-07-07T18:40:32.356308+08:00",
    "user_metadata": null
}

@kangmingtay kangmingtay added the enhancement New feature or request label Jul 7, 2021
@kangmingtay kangmingtay requested a review from awalias July 7, 2021 10:43
@kangmingtay kangmingtay self-assigned this Jul 7, 2021
Copy link
Copy Markdown
Member

@awalias awalias left a comment

Choose a reason for hiding this comment

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

tested everything and it works great!

Comment thread api/mail.go Outdated
Comment thread api/invite.go
Comment on lines +41 to +55
if user != nil {
if user.IsConfirmed() {
return unprocessableEntityError(DuplicateEmailMsg)
}
} else {
signupParams := SignupParams{
Email: params.Email,
Data: params.Data,
Aud: aud,
Provider: "email",
}
user, err = a.signupNewUser(ctx, tx, &signupParams)
if err != nil {
return err
}
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Bundled fix for #134 as well for convenience. If a user has been signed up but not confirmed yet, an admin should still be able to send out invite links to the same user.

@awalias awalias merged commit 22c9152 into master Jul 14, 2021
@awalias awalias deleted the feat/generate-email-links branch July 14, 2021 02:56
@github-actions
Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 1.11.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

uxodb pushed a commit to uxodb/auth that referenced this pull request Nov 13, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request released

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants