Skip to content

Commit a41f8ce

Browse files
moves relogin logic to upper level
1 parent 525332e commit a41f8ce

File tree

1 file changed

+18
-25
lines changed

1 file changed

+18
-25
lines changed

webapp/packages/plugin-authentication/src/Dialog/useAuthDialogState.ts

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
type AuthProviderConfiguration,
1616
AuthProvidersResource,
1717
type IAuthCredentials,
18+
type ILoginOptions,
1819
} from '@cloudbeaver/core-authentication';
1920
import { ConfirmationDialog, useObservableRef, useResource } from '@cloudbeaver/core-blocks';
2021
import { useService } from '@cloudbeaver/core-di';
@@ -201,7 +202,6 @@ export function useAuthDialogState(accessRequest: boolean, providerId: string |
201202
async login(linkUser: boolean, provider?: AuthProvider, configuration?: AuthProviderConfiguration): Promise<void> {
202203
provider = (provider || state.activeProvider) ?? undefined;
203204
configuration = (configuration || state.activeConfiguration) ?? undefined;
204-
const isFederatedLogin = !!provider?.federated && !!configuration;
205205

206206
if (!provider || this.authenticating) {
207207
return;
@@ -224,10 +224,10 @@ export function useAuthDialogState(accessRequest: boolean, providerId: string |
224224
try {
225225
this.state.setActiveProvider(provider, configuration ?? null);
226226

227-
if (isFederatedLogin) {
228-
await this.federatedLogin(provider, configuration!);
227+
if (provider.federated && configuration) {
228+
await this.federatedLogin(provider, configuration);
229229
} else {
230-
await authInfoService.login(provider.id, {
230+
const options: ILoginOptions = {
231231
configurationId: configuration?.id,
232232
credentials: {
233233
...state.credentials,
@@ -239,35 +239,28 @@ export function useAuthDialogState(accessRequest: boolean, providerId: string |
239239
},
240240
forceSessionsLogout: state.forceSessionsLogout,
241241
linkUser,
242-
});
242+
};
243+
244+
try {
245+
await authInfoService.login(provider.id, options);
246+
} catch (exception: any) {
247+
const gqlError = errorOf(exception, GQLError);
248+
249+
if (gqlError?.errorCode === EServerErrorCode.invalidCredentials) {
250+
await authInfoService.login(provider.id, {
251+
...options,
252+
hasOldHash: true,
253+
});
254+
}
255+
}
243256
}
244257
} catch (exception: any) {
245258
const gqlError = errorOf(exception, GQLError);
246-
const shouldReloginWithOldHash = !isFederatedLogin && gqlError?.errorCode === EServerErrorCode.invalidCredentials;
247259

248260
if (gqlError?.errorCode === EServerErrorCode.tooManySessions) {
249261
state.isTooManySessions = true;
250262
}
251263

252-
if (shouldReloginWithOldHash) {
253-
try {
254-
await authInfoService.login(provider.id, {
255-
configurationId: configuration?.id,
256-
credentials: {
257-
...state.credentials,
258-
credentials: {
259-
...state.credentials.credentials,
260-
user: state.credentials.credentials['user']?.trim(),
261-
password: state.credentials.credentials['password']?.trim(),
262-
},
263-
},
264-
forceSessionsLogout: state.forceSessionsLogout,
265-
linkUser,
266-
hasOldHash: true,
267-
});
268-
} catch {}
269-
}
270-
271264
if (this.destroyed) {
272265
notificationService.logException(exception, 'Login failed');
273266
} else {

0 commit comments

Comments
 (0)