jolly-ocean-26344
05/07/2025, 5:58 PM@ory/client-fetch
code -- are there any examples?
At the moment, we have the below code snippet; the updateLoginFlow
call's network request returns a 422
with a redirect_browser_to
parameter, but for some reason that isn't returned in the actual ory client-fetch
call so I can't pass it back to the client to perform the redirect. Note that I'm logging things in the handleOryCall
script (which is necessary because sometimes these calls throw errors when they actually just succeed with a 400 or similar).
Any ideas? Is there a different suggested approach?
const { data: flow } = await handleOryCall<LoginFlow>(
async () =>
await ory.createBrowserLoginFlow({
returnTo: '/login',
}),
'initialize Google login flow',
);
<http://logger.info|logger.info>('flow');
<http://logger.info|logger.info>(JSON.stringify(flow, undefined, 2));
const csrfTokenNode = flow?.ui?.nodes.find(
(node: UiNode) =>
node.attributes.node_type === 'input' &&
(node.attributes as UiNodeInputAttributes).name === 'csrf_token',
);
const csrfToken = csrfTokenNode?.attributes
? ((csrfTokenNode.attributes as UiNodeInputAttributes).value as string)
: undefined;
if (!csrfToken) {
throw new Error('CSRF token not found in flow');
}
const providerNode = flow?.ui?.nodes.find(
(node: UiNode) =>
node.attributes.node_type === 'input' &&
(node.attributes as UiNodeInputAttributes).name === 'provider',
);
const providerId = providerNode?.attributes
? ((providerNode.attributes as UiNodeInputAttributes).value as string)
: '';
const response = await handleOryCall<SuccessfulNativeLogin>(
() =>
ory.updateLoginFlow({
flow: flow?.id ?? '',
updateLoginFlowBody: {
method: 'oidc', // OpenID Connect method
provider: providerId,
csrf_token: csrfToken,
},
}),
'update login flow to get Google auth',
);
bland-eye-99092
05/07/2025, 6:06 PMbut for some reason that isn't returnedwhat are you seeing instead?
jolly-ocean-26344
05/07/2025, 6:10 PM{
"statusCode": 422,
"error": {
"response": {},
"name": "ResponseError"
}
}
bland-eye-99092
05/07/2025, 6:24 PM