kratos
kratos copied to clipboard
Different Email templates based on identity traits (created_at and updated_at are always the same)
Preflight checklist
- [X] I could not find a solution in the existing issues, docs, nor discussions.
- [X] I agree to follow this project's Code of Conduct.
- [X] I have read and am following this repository's Contribution Guidelines.
- [ ] This issue affects my Ory Cloud project.
- [X] I have joined the Ory Community Slack.
- [ ] I am signed up to the Ory Security Patch Newsletter.
Describe the bug
As mentioned in this discussion: https://github.com/ory/kratos/discussions/2061 I hoped to have different email templates (supported with advanced email templates in >= v0.8) based on the state of the Identity
. Foremost I wanted to display a "welcome message" when a user first registered and some sort of "email changed" message when the user decides to change their email address and receive the verification link again. As suggested in the discussion by @vinckr I tried the following:
{{- if eq .Identity.created_at .Identity.updated_at -}}
<h1>Welcome</h1>
{{- else -}}
<h1>Email Changed</h1>
{{- end -}}
I noticed that this always results in the first block being displayed even when changing the email address (multiple times). Then I had a look at the identity object and noticed no matter how often I would change the email address the created_at
and updated_at
fields always stayed the same.
If the issue is not reproducable I would also be happy with a suggestion how to differentiate a registration
and a settings
flow to have different email templates shown 😁
Reproducing the bug
- Spin up a kratos version >= 0.8 (I used v0.8.2-alpha.1)
- Configure at least the email trait as a credential password identifier (see configuration below)
- Provide a simple email template that has the condition I showed above
- Register a new Identity
- Check if the welcome message is displayed in the email
- Try to change the email
- The welcome message will still be displayed in the email
Expected behavior would be that the email contains the "email changed" message.
Relevant log output
No response
Relevant configuration
{
"$id": "user.v1",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "User (v1)",
"type": "object",
"properties": {
"traits": {
"type": "object",
"properties": {
"email": {
"type": "string",
"format": "email",
"title": "E-Mail",
"minLength": 3,
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
}
},
"verification": {
"via": "email"
},
"recovery": {
"via": "email"
}
}
},
"username": {
"type": "string",
"title": "Username",
"pattern": "^[0-9\\._\\-]*[a-z]{3}[a-z0-9\\._\\-]*$",
"minLength": 3,
"maxLength": 30,
"ory.sh/kratos": {
"credentials": {
"password": {
"identifier": true
}
}
}
},
"first_name": {
"type": "string",
"title": "First Name",
"minLength": 2,
"maxLength": 30
},
"last_name": {
"type": "string",
"title": "Last Name",
"minLength": 2,
"maxLength": 30
},
"birthday": {
"type": "string",
"title": "Birthday",
"format": "date"
}
},
"required": [
"email",
"username",
"tos_accepted"
],
"additionalProperties": false
}
}
}
Version
v0.8.2-alpha.1
On which operating system are you observing this issue?
Windows
In which environment are you deploying?
Kubernetes with Helm
Additional Context
I only mentioned the usage for created_at
and updated_at
inside email templates but I think this issue goes beyond a stylistic improvement.
Hi team! @aeneasr @vinckr any updates about this? I'm using Kratos 0.13.0
and the issue is still there, I don't see that
updated_at
date is being changed for a PATCH or PUT request to change the identity...
I confirm this still the case in Kratos v 1.0.0.
My use case is settings flow and settings page UI. The updated_at
value is never (nomen omen) updated when modifying traits of password so it's now meaningless to display this information.
still the case in Kratos v1.1.0
Workaround: I'm using like metadata_public.profile_updated_at to achieve this.
{{- if .Identity.metadata_public.profile_updated_at -}}
<h1>Email Changed</h1>
{{- else -}}
<h1>Welcome</h1>
{{- end -}}