Skip to content

Commit ac34158

Browse files
Update login form for federated logout (#1644)
<!-- Ensure the title clearly reflects what was changed. Provide a clear and concise description of the changes made. The PR should only contain the changes related to the issue, and no other unrelated changes. --> Fixes OPS-2947 Need it for federated login --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent 940f221 commit ac34158

4 files changed

Lines changed: 23 additions & 7 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import { FlagsMap } from '@/app/lib/flags-api';
2+
3+
export const getFederatedUrlBasedOnFlags = (flags: FlagsMap) =>
4+
flags.FEDERATED_LOGIN_ENABLED
5+
? (flags.FRONTEGG_URL as string | undefined)
6+
: undefined;

packages/react-ui/src/app/common/guards/allow-logged-in-user-only-guard.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { jwtDecode } from 'jwt-decode';
44
import { Suspense, useEffect } from 'react';
55
import { Navigate, useLocation, useNavigate } from 'react-router-dom';
66

7+
import { getFederatedUrlBasedOnFlags } from '@/app/common/auth/lib/utils';
78
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
89
import { platformHooks } from '@/app/common/hooks/platform-hooks';
910
import { projectHooks } from '@/app/common/hooks/project-hooks';
@@ -61,7 +62,7 @@ export const AllowOnlyLoggedInUserOnlyGuard = ({
6162
await authenticationSession.logOut({
6263
userInitiated: false,
6364
navigate,
64-
federatedLoginUrl: flags?.FRONTEGG_URL as string | undefined,
65+
federatedLoginUrl: getFederatedUrlBasedOnFlags(flags),
6566
});
6667
} catch (e) {
6768
if (isMounted) {

packages/react-ui/src/app/features/authentication/components/sign-in-form.tsx

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import { t } from 'i18next';
1515
import { SubmitHandler, useForm } from 'react-hook-form';
1616
import { Link, useNavigate } from 'react-router-dom';
1717

18+
import { getFederatedUrlBasedOnFlags } from '@/app/common/auth/lib/utils';
1819
import { flagsHooks } from '@/app/common/hooks/flags-hooks';
1920
import { HttpError, api } from '@/app/lib/api';
2021
import { authenticationApi } from '@/app/lib/authentication-api';
@@ -26,7 +27,7 @@ import {
2627
SignInRequest,
2728
emailRegex,
2829
} from '@openops/shared';
29-
import { useEffectOnce } from 'react-use';
30+
import { useEffect } from 'react';
3031
import { navigationUtil } from '../../../lib/navigation-util';
3132

3233
const SignInSchema = Type.Object({
@@ -52,11 +53,17 @@ const SignInForm: React.FC = () => {
5253
mode: 'onChange',
5354
});
5455

55-
useEffectOnce(() => {
56+
const { data: flags } = flagsHooks.useFlags();
57+
58+
useEffect(() => {
59+
if (!flags) {
60+
return;
61+
}
5662
authenticationSession.logOut({
5763
userInitiated: false,
64+
federatedLoginUrl: getFederatedUrlBasedOnFlags(flags),
5865
});
59-
});
66+
}, [flags]);
6067

6168
const { data: edition } = flagsHooks.useFlag(FlagId.EDITION);
6269
const { data: showSignUpLink } = flagsHooks.useFlag(FlagId.SHOW_SIGN_UP_LINK);

packages/react-ui/src/app/interceptors.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { getFederatedUrlBasedOnFlags } from '@/app/common/auth/lib/utils';
12
import { API_URL, isUrlRelative } from '@/app/lib/api';
23
import { authenticationSession } from '@/app/lib/authentication-session';
34
import axios, { AxiosError, HttpStatusCode } from 'axios';
@@ -60,12 +61,13 @@ axios.interceptors.response.use(
6061
if (url !== OPENOPS_CLOUD_USER_INFO_API_URL && !isSignInRoute) {
6162
console.warn('JWT expired logging out');
6263

63-
const flags = queryClient.getQueryData<FlagsMap>([QueryKeys.flags]);
64+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
65+
const flags = queryClient.getQueryData<FlagsMap>([QueryKeys.flags])!;
6466
authenticationSession.logOut({
6567
userInitiated: false,
66-
federatedLoginUrl: flags?.FRONTEGG_URL as string | undefined,
68+
federatedLoginUrl: getFederatedUrlBasedOnFlags(flags),
6769
});
68-
if (!flags?.FRONTEGG_URL) {
70+
if (!flags?.FEDERATED_LOGIN_ENABLED) {
6971
window.location.reload();
7072
}
7173
}

0 commit comments

Comments
 (0)