authgear / authgear/authgear-server
Support standard attributes and custom attributes in templates
- Dominant language
- Go
- Stars
- 2k
- Forks
- 125
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 32
Description
Support using user profile attributes (standard attributes and custom attributes) in email and SMS message templates, so end users can receive personalized messages (e.g. "Dear {given_name}").
This is more useful when our workflow supports filling user profile during signup
This is more useful once the sign-up workflow supports filling in the user profile during signup.
## Current state (as of 2026-06)
User profile data is **not** available in email/SMS templates today. The template rendering context (`pkg/lib/translation/variables.go` — `PreparedTemplateVariables`) only exposes:
* `.Code`, `.Link` (OTP / magic-link / reset-link)
* `.Email`, `.Phone` (the recipient target only)
* `.Password` (admin-generated, send-password emails)
* `.HasPassword`, `.Host`, and UI-param fields (`.ClientID`, `.ClientName`, `.State`, `.XState`, `.UILocales`)
* `{{ template "app.name" }}`
No standard claims (`given_name`, `family_name`, `name`, `nickname`, …) or custom attributes are passed in. The only place standard claims are read in the send path (`pkg/lib/feature/forgotpassword/sender.go`) uses them solely to resolve the recipient's email address — they are not injected into the template.
## Implementation outline
The three message senders construct a `translation.PartialTemplateVariables`:
* `pkg/lib/authn/otp/sender.go` (`setupTemplateContext`)
* `pkg/lib/feature/forgotpassword/sender.go`
* `pkg/lib/usage/usage_alert_email_service.go`
To support profile attributes:
1. Add the user profile (standard + custom attributes) to `PartialTemplateVariables` / `PreparedTemplateVariables`, populated from the user's claims in the senders (where a user ID is available).
2. Decide on the template-facing shape and naming (e.g. a `.UserProfile` map keyed by profile pointer) and how missing attributes fall back.
3. Provide hints/examples in the Portal template editor.
4. Update the public docs (Custom Email and SMS Templates) once shipped.
Terminology: use "User Profile" for the object obtainable from `/oauth2/userinfo` (see [DEV-2594](https://linear.app/authgear/issue/DEV-2594/unify-terminology-of-specs-or-docs-for-user-profile-pointers-and-go)).
Contributor guide
Research direction
Start with pkg/lib/translation/variables.go and trace PartialTemplateVariables and PreparedTemplateVariables into pkg/lib/authn/otp/sender.go, pkg/lib/feature/forgotpassword/sender.go, and pkg/lib/usage/usage_alert_email_service.go. Determine the template-facing profile shape and missing-attribute behavior, then review the Portal template editor and Custom Email and SMS Templates documentation. Done means profile attributes are available in email and SMS templates and the examples and public docs explain their use.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- authentication, backend, documentation
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100