hey everyone, now sure where to put this, so I cho...
# ory-network
w
hey everyone, now sure where to put this, so I chose this channel 🥲 We have next.js app to host our authentication pages, and we are using Ory react elements. I have 2 issues with the UI redirects: Issue with verification UI redirect For the verification flow redirect after verification works strange: I have
Custom domain: https://auth.mtpc.com
and I have
Custom UI Base URL: https://ui.mtpc.com
. If I set in 'Custom UI URLs for Ory Kratos' the field
Verification UI
to just path
/verification
, it would redirect me to custom domain, not custom ui base url, like this:
https://auth.mtpc.com/verification?flow=...
, so I have to put the whole url to these fields, such as
https://ui.mtpc.com/verification
. Is this correct? The default states are
/ui/verification
, so I assumed it would take custom ui base url + path Issue with recovery flow When users enter the recovery code, the redirect fails and this is the error from the logs (I recucted the URLs for a bit better readability):
Copy code
Error [ResponseError]: The Ory API endpoint returned a response code the SDK does not know how to handle. Please check the network tab for more information:

{
  "error": {
    "id": "session_aal2_required",
    "code": 403,
    "status": "Forbidden",
    "reason": "An active session was found but it does not fulfill the requested Authenticator Assurance Level. Please verify yourself with a second factor to resolve this issue.",
    "details": {
      "redirect_browser_to": "...."
    },
    "message": "Session does not fulfill the requested Authenticator Assurance Level"
  },
  "redirect_browser_to": "...."
}
hey @magnificent-energy-493 any chance for someone to look into it? 🙏
b
Hi, The error you mentioned
session_aal2_required
occurs when there is an active session, but it does not fulfill the required Authenticator Assurance Level 2 (AAL2), which means a second factor authentication is required. This typically happens in flows that require multi-factor authentication (MFA), and the current session doesn't meet that requirement. The frontend/backend needs to handle this by redirecting the user to perform the second factor authentication or step-up authentication flow.
w
hi, thank you for the reply! but I still can’t figure out how we can handle the redirect: 1. I request email recovery, while not being logged in 2. I enter recovery code, I am logged in immediately after using the code, and I am redirected to the settings page automatically. but as we do require 2FA for settings, it fails because it won’t redirect me to 2FA before redirecting to settings. shouldn’t this be handled on SDK side — if 2FA is required for settings, redirect to the 2FA flow?
b
Hi Anastasia, After recovery, the session is created at AAL1, and if settings require AAL2, you must handle the 403 and redirect to the 2FA flow using the
redirect_browser_to
URL. This is not handled automatically by the SDK, but is expected to be implemented in your application logic. So, the recommended approach is to catch the 403 error, check for
session_aal2_required
error and use the
redirect_browser_to
URL to send the user to the 2FA flow. Let me know if this works for you.
Actually, I will also confirm if this is the best way to go with elements. I'll let you know once get an update.
w
thank you!
b
Hi Anastasia, This functionality is built into Elements by default through the
OrySelfServiceFlowCard
component. The component automatically handles login form submissions and apply the appropriate behavior based on the response. So typically when AAL2 is required, the hook receives a 422 response from Kratos, extracts the redirect URL from the response body, and performs the redirection. If you are using
OrySelfServiceFlowCard
component, and still getting this error, can you please some more context on the error that you are getting like logs, example snippet and/or HAR file?
w
hi! We are using just the
Recovery
component from
import { Recovery } from '@ory/elements-react/theme'
where we pass flow from
getRecoveryFlow
function
b
Ok, it should be handled there in Recovery Component as far as I know. Can you please send some more details on the error like logs, HAR file etc
Also a question on your current scenario/use-case, after you complete recovery, instead of going directly to the settings, if you go the home page and then to the settings page, does it give the 2 factor login page? or it gives the same error?
w
if I go to home page — everything works, we are logged in, this is not a problem
this is a HAR file with requests done by Ory while recovering, and error from the logs
👀 1
maybe this will help as well, this is my flow that is passed to recovery component, and I see that
return_to
is correct here (I would assume this where it should take me, not to settings actually):
Copy code
{
  "active": "code",
  "expires_at": {},
  "id": "ebc908d9-3b12-4583-b5ef-fabb75b7f9c9",
  "issued_at": {},
  "request_url": "http://localhost:3000/self-service/recovery/browser?app=creator&return_to=https%3A%2F%2Fapp.metapic.dev",
  "return_to": "https://app.metapic.dev",
  "state": "sent_email",
  "type": "browser",
  "ui": {
    "action": "http://localhost:3000/self-service/recovery?flow=ebc908d9-3b12-4583-b5ef-fabb75b7f9c9",
    "messages": [
      {
        "id": 1060003,
        "text": "An email containing a recovery code has been sent to the email address you provided. If you have not received an email, check the spelling of the address and make sure to use the address you registered with.",
        "type": "info"
      }
    ],
    "method": "POST",
    "nodes": [
      {
        "attributes": {
          "disabled": false,
          "name": "csrf_token",
          "node_type": "input",
          "required": true,
          "type": "hidden",
          "value": "Z+lXb/X/5S/mnp80HW/1+FC6MBRfrtzuTvb74Yqu1NB+ixsqe66Exulq2VjcK+DDnnhzOBlXOStN7baL+r2gXg=="
        },
        "group": "default",
        "messages": [],
        "meta": {},
        "type": "input"
      },
      {
        "attributes": {
          "disabled": false,
          "maxlength": 6,
          "name": "code",
          "node_type": "input",
          "pattern": "[0-9]+",
          "required": true,
          "type": "text"
        },
        "group": "code",
        "messages": [],
        "meta": {
          "label": {
            "id": 1070010,
            "text": "Recovery code",
            "type": "info"
          }
        },
        "type": "input"
      },
      {
        "attributes": {
          "disabled": false,
          "name": "method",
          "node_type": "input",
          "type": "hidden",
          "value": "code"
        },
        "group": "code",
        "messages": [],
        "meta": {},
        "type": "input"
      },
      {
        "attributes": {
          "disabled": false,
          "name": "method",
          "node_type": "input",
          "type": "submit",
          "value": "code"
        },
        "group": "code",
        "messages": [],
        "meta": {
          "label": {
            "id": 1070009,
            "text": "Continue",
            "type": "info"
          }
        },
        "type": "input"
      },
      {
        "attributes": {
          "disabled": false,
          "name": "email",
          "node_type": "input",
          "type": "submit",
          "value": "[email protected]"
        },
        "group": "code",
        "messages": [],
        "meta": {
          "label": {
            "id": 1070008,
            "text": "Resend code",
            "type": "info"
          }
        },
        "type": "input"
      }
    ]
  }
}
👀 1
b
I will look into this.
💛 1
w
hey, any updates on this? or any workaround to redirect back to
retunr_to
?
b
Hey Anastasia, We're working on a fix for this. Once that gets done, I'll let you know.
w
hi, thank you! we have a release with strict deadline, can you please give an approx. eta?
m
What is the go-live date that you are looking to meet? Generally we don't give out ETA for fixes or features - but we will definitely do our best to meet your timeline.
w
I've chatted with Parth, we will have to do a workaround, because the release is very soon (sooner than the fix will arrive)
hi, just to make sure you understood the full picture with the issue, there are 2 bugs on the recovery component: 1. It breaks when redirected to settings with AAL2 requirements (logs attached and what we've discussed) 2. It ignores
return_to
url passed to the flow (therefore we have the bug with the settings page, as it redirects users to settings instead of
return_to
)
👀 1