Hi, I'm trying to build a custom UI for the recove...
# ory-network
t
Hi, I'm trying to build a custom UI for the recovery flow. I'm pretty much using this example verbatim: https://www.ory.com/docs/kratos/bring-your-own-ui/custom-ui-basic-integration#recovery I have these set on my project: Enable account recovery = true Recovery strategy = Magic links In Dev Tools, when I load the page I see:
Copy code
Req:
GET http://localhost:4000/self-service/recovery/browser?return_to=...

Res:
{
    "id": "...",
    "type": "browser",
    "expires_at": "2025-11-26T07:19:46.179066985Z",
    "issued_at": "2025-11-26T06:49:46.179066985Z",
    "request_url": "http://localhost:4000/self-service/recovery/browser?return_to=...",
    "return_to": "http://localhost:3000",
    "active": "link",
    "ui": {
        "action": "http://localhost:4000/self-service/recovery?flow=...",
        "method": "POST",
        "nodes": [
            {
                "type": "input",
                "group": "default",
                "attributes": {
                    "name": "csrf_token",
                    "type": "hidden",
                    "value": "...",
                    "required": true,
                    "disabled": false,
                    "node_type": "input"
                },
                "messages": [],
                "meta": {}
            },
            {
                "type": "input",
                "group": "link",
                "attributes": {
                    "name": "email",
                    "type": "email",
                    "required": true,
                    "disabled": false,
                    "node_type": "input"
                },
                "messages": [],
                "meta": {
                    "label": {
                        "id": 1070007,
                        "text": "Email",
                        "type": "info"
                    }
                }
            },
            {
                "type": "input",
                "group": "link",
                "attributes": {
                    "name": "method",
                    "type": "submit",
                    "value": "link",
                    "disabled": false,
                    "node_type": "input"
                },
                "messages": [],
                "meta": {
                    "label": {
                        "id": 1070009,
                        "text": "Continue",
                        "type": "info"
                    }
                }
            }
        ]
    },
    "state": "recovery_awaiting_address"
}
When I enter an email address and submit, I see:
Copy code
Req:
POST http://localhost:4000/self-service/recovery?flow=...
Body = {"email":"...","csrf_token":"...","method":"link"}

Res:
Response 303 
Location = http://localhost:4000/recovery?flow=...
What's going on here? Shouldn't the endpoint be returning JSON, not a 303?
I can replicate the issue using just the example CURL statements (putting in the appropriate API endpoint, email, csrf_token, and flow. So is there a bug with the Magic link recovery strategy? Something else in my project config that's incompatible?
s
are you setting the
Accept
header to
application/json
?
t
With the CURL commands, yes. I’m copy/pasting the examples and filling in the variables. For my actual code, I’m using @ory/client, like in the example. This is setting Accept header.
s
did you try if the same happens when using codes instead?
t
Codes work!
But we have a product requirement to use magic links.
s
ok then this is some bug
one thing you can do when you're building a custom UI anyway is using codes, but adding them as query params to pre-fill the inputs so e.g. create code
1234
, but then send the email as
Go to https://example.com?code=1234 to recover your account
the UI would then pre-fill the code from the query, potentially not showing it to the user at all this is generally better than magic links, as it allows you to control the step between the click and the actual submission, which can make it more reliable
t
hah, you beat me to it. that was going to be my question
i'll give that a try
s
the main problem with links is email programs or providers opening links, and therefore invalidating them
by adding a simple "Confirm" button that the user needs to click you can completely fix that
and also avoid the bug 😉
t
great idea
in our https://example.com?code=1234 view, would we be able to have the new password field + submit? or are you saying we'd need a confirm button, then a new password field + submit?
s
you need to submit the code first, then you get redirected to a settings flow where the password field is
but the UI can do fancy stuff and auto-submit
t
that's true!
s
eg display the password field, but on submit first submit the code, then submit the password
when doing that server side, you just need to add your own csrf protection
t
would you also need flow in here?
Go to https://example.com?code=1234 to recover your account
this is what i have now:
If this was you, please use the following link to proceed: https://DOMAIN.com/recovery?code={{ .RecoveryCode }}