Skip to content

Commit

Permalink
fix(chat): revert login/logout changes (#2981)
Browse files Browse the repository at this point in the history
Co-authored-by: Irina_Kartun <[email protected]>
  • Loading branch information
IlyaBondar and irinakartun authored Jan 23, 2025
1 parent 392fdea commit 49183c5
Show file tree
Hide file tree
Showing 17 changed files with 45 additions and 361 deletions.
44 changes: 17 additions & 27 deletions apps/chat-e2e/src/tests/announcementBanner.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@ dialTest(
'Banner is shown.\n' +
'Banner text contains html link.\n' +
"Banner doesn't appear if to close it",
async (
{
dialHomePage,
conversationData,
dataInjector,
chatBar,
promptBar,
conversations,
banner,
header,
appContainer,
accountSettings,
accountDropdownMenu,
confirmationDialog,
providerLogin,
setTestIds,
},
testInfo,
) => {
async ({
dialHomePage,
conversationData,
dataInjector,
chatBar,
promptBar,
conversations,
banner,
header,
appContainer,
accountSettings,
accountDropdownMenu,
confirmationDialog,
providerLogin,
setTestIds,
}) => {
setTestIds('EPMRTC-1576', 'EPMRTC-1580', 'EPMRTC-1577');
const username =
process.env.E2E_USERNAME!.split(',')[+process.env.TEST_PARALLEL_INDEX!];
let conversation: Conversation;
let chatBarBounding;
let promptBarBounding;
Expand Down Expand Up @@ -149,12 +144,7 @@ dialTest(
await accountDropdownMenu.selectMenuOption(AccountMenuOptions.logout);
await confirmationDialog.confirm();
await providerLogin.navigateToCredentialsPage();
await providerLogin.authProviderLogin(
testInfo,
username,
process.env.E2E_PASSWORD!,
false,
);
await dialHomePage.waitForPageLoaded({ skipSidebars: true });
await expect
.soft(banner.getElementLocator(), ExpectedMessages.bannerIsClosed)
.toBeHidden();
Expand Down
5 changes: 2 additions & 3 deletions apps/chat-e2e/src/tests/overlay/overlayAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,8 @@ for (let i = 0; i < overlayUsernames.length; i++) {

const loginPage = new LoginPage(newPage);
await newPage.waitForLoadState();
if (await loginPage.auth0SignInButton.isVisible()) {
await loginPage.auth0SignInButton.click();
}
await loginPage.auth0SignInButton.click();

const auth0Page = new Auth0Page(newPage);
await newPage.waitForLoadState();
const auth0Form = auth0Page.getAuth0();
Expand Down
5 changes: 2 additions & 3 deletions apps/chat-e2e/src/ui/actions/auth0Login.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { LocalStorageManager } from '@/src/core/localStorageManager';
import { ProviderLogin } from '@/src/ui/actions/providerLogin';
import { Auth0Page } from '@/src/ui/pages/auth0Page';
import { LoginPage } from '@/src/ui/pages/loginPage';
import { BaseElement } from '@/src/ui/webElements';

export class Auth0Login extends ProviderLogin<Auth0Page> {
constructor(
Expand All @@ -13,7 +12,7 @@ export class Auth0Login extends ProviderLogin<Auth0Page> {
super(loginPage, authProviderPage, localStorageManager);
}

getSignInButton(): BaseElement {
return this.loginPage.auth0SignInButton;
public async navigateToCredentialsPage() {
await this.loginPage.auth0SignInButton.click();
}
}
5 changes: 2 additions & 3 deletions apps/chat-e2e/src/ui/actions/azureADLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { LocalStorageManager } from '@/src/core/localStorageManager';
import { ProviderLogin } from '@/src/ui/actions/providerLogin';
import { AzureADPage } from '@/src/ui/pages/azureADPage';
import { LoginPage } from '@/src/ui/pages/loginPage';
import { BaseElement } from '@/src/ui/webElements';

export class AzureADLogin extends ProviderLogin<AzureADPage> {
constructor(
Expand All @@ -13,7 +12,7 @@ export class AzureADLogin extends ProviderLogin<AzureADPage> {
super(loginPage, authProviderPage, localStorageManager);
}

getSignInButton(): BaseElement {
return this.loginPage.keycloakSignInButton;
public async navigateToCredentialsPage() {
await this.loginPage.keycloakSignInButton.click();
}
}
5 changes: 2 additions & 3 deletions apps/chat-e2e/src/ui/actions/keycloakLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { LocalStorageManager } from '@/src/core/localStorageManager';
import { ProviderLogin } from '@/src/ui/actions/providerLogin';
import { KeycloakPage } from '@/src/ui/pages';
import { LoginPage } from '@/src/ui/pages/loginPage';
import { BaseElement } from '@/src/ui/webElements';

export class KeycloakLogin extends ProviderLogin<KeycloakPage> {
constructor(
Expand All @@ -13,7 +12,7 @@ export class KeycloakLogin extends ProviderLogin<KeycloakPage> {
super(loginPage, authProviderPage, localStorageManager);
}

getSignInButton(): BaseElement {
return this.loginPage.keycloakSignInButton;
public async navigateToCredentialsPage() {
await this.loginPage.keycloakSignInButton.click();
}
}
12 changes: 2 additions & 10 deletions apps/chat-e2e/src/ui/actions/providerLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import { API } from '@/src/testData';
import { LoginInterface } from '@/src/ui/actions/loginInterface';
import { BasePage } from '@/src/ui/pages/basePage';
import { LoginPage } from '@/src/ui/pages/loginPage';
import { BaseElement } from '@/src/ui/webElements';
import { TestInfo } from '@playwright/test';

export abstract class ProviderLogin<T extends BasePage & LoginInterface> {
Expand All @@ -21,14 +20,7 @@ export abstract class ProviderLogin<T extends BasePage & LoginInterface> {
this.localStorageManager = localStorageManager;
}

abstract getSignInButton(): BaseElement;

async navigateToCredentialsPage(): Promise<void> {
const signInButton = this.getSignInButton();
if (await signInButton.isVisible()) {
await signInButton.click();
}
}
abstract navigateToCredentialsPage(): Promise<void>;

public async login(
testInfo: TestInfo,
Expand All @@ -53,7 +45,7 @@ export abstract class ProviderLogin<T extends BasePage & LoginInterface> {
: await this.loginPage.navigateToBaseUrl();
}

public async authProviderLogin(
protected async authProviderLogin(
testInfo: TestInfo,
username: string,
password: string,
Expand Down
8 changes: 4 additions & 4 deletions apps/chat/src/components/Header/User/UserDesktop.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
/*eslint-disable @next/next/no-img-element*/
import { IconSettings } from '@tabler/icons-react';
import { signIn, useSession } from 'next-auth/react';
import { signIn, signOut, useSession } from 'next-auth/react';
import { useCallback, useState } from 'react';

import { useTranslation } from 'next-i18next';

import { customSignOut } from '@/src/utils/auth/signOut';

import { Translation } from '@/src/types/translation';

import { useAppDispatch } from '@/src/store/hooks';
Expand All @@ -29,7 +27,9 @@ export const UserDesktop = Inversify.register('UserDesktop', () => {
const { data: session } = useSession();
const dispatch = useAppDispatch();
const handleLogout = useCallback(() => {
session ? customSignOut() : signIn('azure-ad', { redirect: true });
session
? signOut({ redirect: true })
: signIn('azure-ad', { redirect: true });
}, [session]);

return (
Expand Down
8 changes: 4 additions & 4 deletions apps/chat/src/components/Header/User/UserMobile.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
/*eslint-disable @next/next/no-img-element*/
import { IconSettings } from '@tabler/icons-react';
import { signIn, useSession } from 'next-auth/react';
import { signIn, signOut, useSession } from 'next-auth/react';
import { useCallback, useState } from 'react';

import { useTranslation } from 'next-i18next';

import classNames from 'classnames';

import { customSignOut } from '@/src/utils/auth/signOut';

import { Translation } from '@/src/types/translation';

import { useAppDispatch, useAppSelector } from '@/src/store/hooks';
Expand Down Expand Up @@ -78,7 +76,9 @@ const Logout = () => {
useState(false);

const handleLogout = useCallback(() => {
session ? customSignOut() : signIn('azure-ad', { redirect: true });
session
? signOut({ redirect: true })
: signIn('azure-ad', { redirect: true });
}, [session]);
return (
<>
Expand Down
64 changes: 0 additions & 64 deletions apps/chat/src/pages/api/auth/federated-logout.ts

This file was deleted.

33 changes: 0 additions & 33 deletions apps/chat/src/pages/auth/signin/index.tsx

This file was deleted.

1 change: 0 additions & 1 deletion apps/chat/src/utils/auth/auth-callbacks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,6 @@ export const callbacks: Partial<
refreshToken: options.account.refresh_token,
providerId: options.account.provider,
userId: options.user.id,
idToken: options.account.id_token,
};
}

Expand Down
4 changes: 1 addition & 3 deletions apps/chat/src/utils/auth/auth-pages.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import { PagesOptions } from 'next-auth';

import { DEFAULT_PROVIDER } from './auth-providers';

export const pages: Partial<PagesOptions> = {
// Put here your custom pages for authentication,
// which will be used by next-auth instead of the default ones
// https://authjs.dev/getting-started/session-management/custom-pages
// ------------------------------------------------------------------
signIn: DEFAULT_PROVIDER ? '/auth/signin' : undefined,
// signIn: '/auth/signin',
// signOut: '/auth/signout',
// error: '/auth/error',
// verifyRequest: '/auth/verify-request',
Expand Down
20 changes: 1 addition & 19 deletions apps/chat/src/utils/auth/auth-providers.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { OAuthProviderType, Provider } from 'next-auth/providers';
import { Provider } from 'next-auth/providers';
import Auth0Provider from 'next-auth/providers/auth0';
import AzureProvider from 'next-auth/providers/azure-ad';
import CognitoProvider from 'next-auth/providers/cognito';
Expand Down Expand Up @@ -156,24 +156,6 @@ const allProviders: (Provider | boolean)[] = [

export const authProviders = allProviders.filter(Boolean) as Provider[];

/**
* Sets the DEFAULT_PROVIDER to the single available provider's ID if:
* - There is only one authentication provider configured.
* - The provider supports federated logout.
*
* This allows us to skip the NextAuth provider selection page and
* directly use the single available provider for authentication.
* By ensuring the provider supports federated logout, we maintain
* proper session management and user experience during logout operations.
*/
const FEDERATED_LOGOUT_PROVIDERS: OAuthProviderType[] = ['auth0', 'keycloak'];

export const DEFAULT_PROVIDER: OAuthProviderType | null =
authProviders.length === 1 &&
FEDERATED_LOGOUT_PROVIDERS.includes(authProviders[0]?.id as OAuthProviderType)
? (authProviders[0]?.id as OAuthProviderType)
: null;

/**
* Is authorization enabled
*
Expand Down
27 changes: 0 additions & 27 deletions apps/chat/src/utils/auth/signOut.ts

This file was deleted.

Loading

0 comments on commit 49183c5

Please sign in to comment.