From 6acc15763f29a49498ad720c2cec70e62f5efab9 Mon Sep 17 00:00:00 2001 From: Jonas Hungershausen Date: Thu, 7 Nov 2024 11:07:47 +0100 Subject: [PATCH] fix: redirect to login if session expired during settings --- .../elements-react/src/util/onSubmitSettings.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/packages/elements-react/src/util/onSubmitSettings.ts b/packages/elements-react/src/util/onSubmitSettings.ts index 36e4f8c7d..4c7e7393f 100644 --- a/packages/elements-react/src/util/onSubmitSettings.ts +++ b/packages/elements-react/src/util/onSubmitSettings.ts @@ -5,6 +5,8 @@ import { FlowType, handleContinueWith, handleFlowError, + isResponseError, + loginUrl, SettingsFlow, settingsUrl, UpdateSettingsFlowBody, @@ -72,4 +74,15 @@ export async function onSubmitSettings( onRedirect, }), ) + .catch((err) => { + if (isResponseError(err)) { + if (err.response.status === 401) { + return onRedirect( + loginUrl(config) + "?return_to=" + settingsUrl(config), + true, + ) + } + throw err + } + }) }