Skip to content

Commit e1119e8

Browse files
authored
fix: verification redirect & continue label (#2905)
This PR resolves an issue with the redirect after a successful verification, if not specified.
1 parent b6c212c commit e1119e8

File tree

12 files changed

+45
-42
lines changed

12 files changed

+45
-42
lines changed

.gitignore

+5
Original file line numberDiff line numberDiff line change
@@ -59,3 +59,8 @@ test/e2e/hydra-kratos-login-consent/hydra-kratos-login-consent
5959
*.log
6060
test/e2e/proxy.json
6161
test/e2e/kratos.*.yml
62+
63+
# Kratos executable
64+
kratos
65+
# VSCode debug artifact
66+
__debug_bin

cmd/clidoc/main.go

+2-1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func init() {
7272
"NewErrorValidationVerificationFlowExpired": text.NewErrorValidationVerificationFlowExpired(aSecondAgo),
7373
"NewInfoSelfServiceVerificationSuccessful": text.NewInfoSelfServiceVerificationSuccessful(),
7474
"NewVerificationEmailSent": text.NewVerificationEmailSent(),
75+
"NewVerificationEmailWithCodeSent": text.NewVerificationEmailWithCodeSent(),
7576
"NewErrorValidationVerificationTokenInvalidOrAlreadyUsed": text.NewErrorValidationVerificationTokenInvalidOrAlreadyUsed(),
7677
"NewErrorValidationVerificationRetrySuccess": text.NewErrorValidationVerificationRetrySuccess(),
7778
"NewErrorValidationVerificationStateFailure": text.NewErrorValidationVerificationStateFailure(),
@@ -122,7 +123,7 @@ func init() {
122123
"NewErrorValidationRecoveryStateFailure": text.NewErrorValidationRecoveryStateFailure(),
123124
"NewInfoNodeInputEmail": text.NewInfoNodeInputEmail(),
124125
"NewInfoNodeResendOTP": text.NewInfoNodeResendOTP(),
125-
"NewInfoNodeLabelReturn": text.NewInfoNodeLabelReturn(),
126+
"NewInfoNodeLabelContinue": text.NewInfoNodeLabelContinue(),
126127
"NewInfoSelfServiceSettingsRegisterWebAuthn": text.NewInfoSelfServiceSettingsRegisterWebAuthn(),
127128
"NewInfoLoginWebAuthnPasswordless": text.NewInfoLoginWebAuthnPasswordless(),
128129
"NewInfoSelfServiceRegistrationRegisterWebAuthn": text.NewInfoSelfServiceRegistrationRegisterWebAuthn(),

selfservice/strategy/code/strategy_verification.go

+4-4
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ func (s *Strategy) verificationHandleFormSubmission(w http.ResponseWriter, r *ht
230230
f.State = verification.StateEmailSent
231231

232232
f.UI = s.createVerificationCodeForm(flow.AppendFlowTo(urlx.AppendPaths(s.deps.Config().SelfPublicURL(r.Context()), verification.RouteSubmitFlow), f.ID).String(), nil, &body.Email)
233-
f.UI.Messages.Set(text.NewVerificationEmailSent())
233+
f.UI.Messages.Set(text.NewVerificationEmailWithCodeSent())
234234
f.UI.SetCSRF(s.deps.GenerateCSRFToken(r))
235235

236236
if err := s.deps.VerificationFlowPersister().UpdateVerificationFlow(r.Context(), f); err != nil {
@@ -290,8 +290,8 @@ func (s *Strategy) verificationUseCode(w http.ResponseWriter, r *http.Request, c
290290
f.UI.Messages.Set(text.NewInfoSelfServiceVerificationSuccessful())
291291
f.UI.
292292
Nodes.
293-
Append(node.NewAnchorField("go-back", returnTo.String(), node.CodeGroup, text.NewInfoNodeLabelReturn()).
294-
WithMetaLabel(text.NewInfoNodeLabelReturn()))
293+
Append(node.NewAnchorField("continue", returnTo.String(), node.CodeGroup, text.NewInfoNodeLabelContinue()).
294+
WithMetaLabel(text.NewInfoNodeLabelContinue()))
295295

296296
if err := s.deps.VerificationFlowPersister().UpdateVerificationFlow(r.Context(), f); err != nil {
297297
return s.retryVerificationFlowWithError(w, r, flow.TypeBrowser, err)
@@ -301,7 +301,7 @@ func (s *Strategy) verificationUseCode(w http.ResponseWriter, r *http.Request, c
301301
}
302302

303303
func (s *Strategy) getRedirectURL(ctx context.Context, f *verification.Flow) *url.URL {
304-
defaultRedirectURL := s.deps.Config().SelfServiceFlowVerificationReturnTo(ctx, f.AppendTo(s.deps.Config().SelfServiceFlowVerificationUI(ctx)))
304+
defaultRedirectURL := s.deps.Config().SelfServiceBrowserDefaultReturnTo(ctx)
305305

306306
verificationRequestURL, err := urlx.Parse(f.GetRequestURL())
307307
if err != nil {

selfservice/strategy/code/strategy_verification_test.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ func TestVerification(t *testing.T) {
191191
var check = func(t *testing.T, actual string) {
192192
assert.EqualValues(t, string(node.CodeGroup), gjson.Get(actual, "active").String(), "%s", actual)
193193
assert.EqualValues(t, email, gjson.Get(actual, "ui.nodes.#(attributes.name==email).attributes.value").String(), "%s", actual)
194-
assertx.EqualAsJSON(t, text.NewVerificationEmailSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
194+
assertx.EqualAsJSON(t, text.NewVerificationEmailWithCodeSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
195195

196196
message := testhelpers.CourierExpectMessage(t, reg, email, "Someone tried to verify this email address")
197197
assert.Contains(t, message.Body, "If this was you, check if you signed up using a different address.")
@@ -292,7 +292,7 @@ func TestVerification(t *testing.T) {
292292
var check = func(t *testing.T, actual string) {
293293
assert.EqualValues(t, string(node.CodeGroup), gjson.Get(actual, "active").String(), "%s", actual)
294294
assert.EqualValues(t, verificationEmail, gjson.Get(actual, "ui.nodes.#(attributes.name==email).attributes.value").String(), "%s", actual)
295-
assertx.EqualAsJSON(t, text.NewVerificationEmailSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
295+
assertx.EqualAsJSON(t, text.NewVerificationEmailWithCodeSent(), json.RawMessage(gjson.Get(actual, "ui.messages.0").Raw))
296296

297297
message := testhelpers.CourierExpectMessage(t, reg, verificationEmail, "Please verify your email address")
298298
assert.Contains(t, message.Body, "please verify your account by entering the following code")
@@ -405,7 +405,7 @@ func TestVerification(t *testing.T) {
405405
require.NoError(t, err)
406406
body := ioutilx.MustReadAll(res.Body)
407407

408-
assert.Equal(t, returnToURL, gjson.GetBytes(body, "ui.nodes.#(attributes.id==go-back).attributes.href").String())
408+
assert.Equal(t, returnToURL, gjson.GetBytes(body, "ui.nodes.#(attributes.id==continue).attributes.href").String())
409409
})
410410

411411
t.Run("case=should respond with replaced error if successful code is submitted again via api", func(t *testing.T) {

test/e2e/cypress/integration/profiles/verification/registration/errors.spec.ts

+1-4
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,7 @@ context("Account Verification Registration Errors", () => {
5757
cy.get(appPrefix(app) + 'input[name="email"]').should("be.empty")
5858
cy.get('input[name="email"]').type(identity.email)
5959
cy.get('button[value="code"]').click()
60-
cy.get('[data-testid="ui/message/1080001"]').should(
61-
"contain.text",
62-
"An email containing a verification",
63-
)
60+
cy.contains("An email containing a verification")
6461
cy.verifyEmail({
6562
expect: { email: identity.email, password: identity.password },
6663
})

test/e2e/cypress/integration/profiles/verification/verify/errors.spec.ts

+3-12
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,7 @@ context("Account Verification Error", () => {
109109
cy.get('input[name="email"]').type(identity.email)
110110
cy.get(`button[value="${s}"]`).click()
111111

112-
cy.get('[data-testid="ui/message/1080001"]').should(
113-
"contain.text",
114-
"An email containing a verification",
115-
)
112+
cy.contains("An email containing a verification")
116113
cy.get(`[name="method"][value="${s}"]`).should("exist")
117114
cy.verifyEmailButExpired({
118115
expect: { email: identity.email },
@@ -124,10 +121,7 @@ context("Account Verification Error", () => {
124121
cy.get('input[name="email"]').type(identity.email)
125122
cy.get(`button[value="${s}"]`).click()
126123

127-
cy.get('[data-testid="ui/message/1080001"]').should(
128-
"contain.text",
129-
"An email containing a verification",
130-
)
124+
cy.contains("An email containing a verification")
131125

132126
cy.getMail().then((mail) => {
133127
const link = parseHtml(mail.body).querySelector("a")
@@ -160,10 +154,7 @@ context("Account Verification Error", () => {
160154
cy.get('input[name="email"]').type(identity.email)
161155
cy.get(`button[value="${s}"]`).click()
162156

163-
cy.get('[data-testid="ui/message/1080001"]').should(
164-
"contain.text",
165-
"An email containing a verification",
166-
)
157+
cy.contains("An email containing a verification")
167158

168159
for (let i = 0; i < 5; i++) {
169160
cy.get("input[name='code']").type((i + "").repeat(8)) // Invalid code

test/e2e/cypress/integration/profiles/verification/verify/success.spec.ts

+2-8
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,7 @@ context("Account Verification Settings Success", () => {
4444
cy.get('input[name="email"]').type(identity.email)
4545
cy.get(`button[value="${s}"]`).click()
4646

47-
cy.get('[data-testid="ui/message/1080001"]').should(
48-
"contain.text",
49-
"An email containing a verification",
50-
)
47+
cy.contains("An email containing a verification")
5148

5249
cy.get(`[name="method"][value="${s}"]`).should("exist")
5350

@@ -59,10 +56,7 @@ context("Account Verification Settings Success", () => {
5956
cy.get('input[name="email"]').type(email)
6057
cy.get(`button[value="${s}"]`).click()
6158

62-
cy.get('[data-testid="ui/message/1080001"]').should(
63-
"contain.text",
64-
"An email containing a verification",
65-
)
59+
cy.contains("An email containing a verification")
6660

6761
cy.getMail().should((message) => {
6862
expect(message.subject.trim()).to.equal(

test/e2e/cypress/support/commands.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1041,8 +1041,8 @@ Cypress.Commands.add(
10411041
cy.get(`button[name="method"][value="code"]`).click()
10421042

10431043
if (redirectTo) {
1044-
cy.get(`[data-testid="node/anchor/go-back"`)
1045-
.contains("Return")
1044+
cy.get(`[data-testid="node/anchor/continue"`)
1045+
.contains("Continue")
10461046
.click()
10471047
cy.url().should("be.equal", redirectTo)
10481048
}

text/id.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,14 @@ const (
8080
InfoNodeLabelVerifyOTP // 1070006
8181
InfoNodeLabelEmail // 1070007
8282
InfoNodeLabelResendOTP // 1070008
83-
InfoNodeLabelReturn // 1070009
83+
InfoNodeLabelContinue // 1070009
8484
)
8585

8686
const (
87-
InfoSelfServiceVerification ID = 1080000 + iota // 1080000
88-
InfoSelfServiceVerificationEmailSent // 1080001
89-
InfoSelfServiceVerificationSuccessful // 1080002
87+
InfoSelfServiceVerification ID = 1080000 + iota // 1080000
88+
InfoSelfServiceVerificationEmailSent // 1080001
89+
InfoSelfServiceVerificationSuccessful // 1080002
90+
InfoSelfServiceVerificationEmailWithCodeSent // 1080003
9091
)
9192

9293
const (

text/id_test.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func TestIDs(t *testing.T) {
3636
assert.Equal(t, 1070006, int(InfoNodeLabelVerifyOTP))
3737
assert.Equal(t, 1070007, int(InfoNodeLabelEmail))
3838
assert.Equal(t, 1070008, int(InfoNodeLabelResendOTP))
39-
assert.Equal(t, 1070009, int(InfoNodeLabelReturn))
39+
assert.Equal(t, 1070009, int(InfoNodeLabelContinue))
4040

4141
assert.Equal(t, 1080000, int(InfoSelfServiceVerification))
4242

@@ -64,4 +64,9 @@ func TestIDs(t *testing.T) {
6464

6565
assert.Equal(t, 4060006, int(ErrorValidationRecoveryCodeInvalidOrAlreadyUsed))
6666
assert.Equal(t, 4070006, int(ErrorValidationVerificationCodeInvalidOrAlreadyUsed))
67+
68+
assert.Equal(t, 1080000, int(InfoSelfServiceVerification))
69+
assert.Equal(t, 1080001, int(InfoSelfServiceVerificationEmailSent))
70+
assert.Equal(t, 1080002, int(InfoSelfServiceVerificationSuccessful))
71+
assert.Equal(t, 1080003, int(InfoSelfServiceVerificationEmailWithCodeSent))
6772
}

text/message_node.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@ func NewInfoNodeLabelSubmit() *Message {
4343
}
4444
}
4545

46-
func NewInfoNodeLabelReturn() *Message {
46+
func NewInfoNodeLabelContinue() *Message {
4747
return &Message{
48-
ID: InfoNodeLabelReturn,
49-
Text: "Return",
48+
ID: InfoNodeLabelContinue,
49+
Text: "Continue",
5050
Type: Info,
5151
}
5252
}

text/message_verification.go

+9
Original file line numberDiff line numberDiff line change
@@ -71,3 +71,12 @@ func NewErrorValidationVerificationCodeInvalidOrAlreadyUsed() *Message {
7171
Context: context(nil),
7272
}
7373
}
74+
75+
func NewVerificationEmailWithCodeSent() *Message {
76+
return &Message{
77+
ID: InfoSelfServiceVerificationEmailWithCodeSent,
78+
Type: Info,
79+
Text: "An email containing a verification code has been sent to the email address you provided.",
80+
Context: context(nil),
81+
}
82+
}

0 commit comments

Comments
 (0)