Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/containers/Avatar/useAvatarETag.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export const useAvatarETag = ({
id
}: {
type?: string;
username: string;
username?: string;
Comment thread
coderabbitai[bot] marked this conversation as resolved.
text: string;
rid?: string;
id: string;
Expand Down
6 changes: 5 additions & 1 deletion app/containers/LoginServices/serviceLogin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,11 @@ export const onPressAppleLogin = async () => {
AppleAuthentication.AppleAuthenticationScope.EMAIL
]
});
await loginOAuthOrSso({ fullName, email, identityToken });
if (!identityToken) {
logEvent(events.ENTER_WITH_APPLE_F);
return;
}
await loginOAuthOrSso({ fullName: fullName ?? {}, email, identityToken });
} catch {
logEvent(events.ENTER_WITH_APPLE_F);
}
Expand Down
9 changes: 5 additions & 4 deletions app/containers/TwoFactor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { useTheme } from '../../theme';
import Button from '../Button';
import sharedStyles from '../../views/Styles';
import styles from './styles';
import { type ICredentials } from '../../definitions';
import { type ILoginCredentials } from '../../definitions';
import { sendEmailCode } from '../../lib/services/restApi';
import { useMasterDetail } from '../../lib/hooks/useMasterDetail';
import Toast from '../Toast';
Expand All @@ -38,7 +38,7 @@ interface IMethods {
}

interface EventListenerMethod {
params?: ICredentials;
params?: ILoginCredentials;
method?: keyof IMethods;
submit?: (param: string) => void;
cancel?: () => void;
Expand Down Expand Up @@ -88,12 +88,13 @@ const TwoFactor = memo(() => {
const method = data.method ? methods[data.method] : null;
const isEmail = data.method === 'email';
const params = data?.params;
const emailCodeRecipient = params && 'user' in params ? params.user : undefined;

const sendEmail = async () => {
try {
if (params?.user) {
if (emailCodeRecipient) {
clearErrors();
const response = await sendEmailCode(params?.user);
const response = await sendEmailCode(emailCodeRecipient);

if (response.success) {
showToast(I18n.t('Two_Factor_Success_message'));
Expand Down
24 changes: 0 additions & 24 deletions app/definitions/ICredentials.ts

This file was deleted.

18 changes: 2 additions & 16 deletions app/definitions/ILoggedUser.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import type Model from '@nozbe/watermelondb/Model';

import { type IUserEmail, type IUserSettings } from './IUser';
import { type IUserEmail } from './IUser';
import { type TStatusSource } from './TStatusSource';
import { type TUserStatus } from './TUserStatus';

export interface ILoggedUser {
id: string;
token: string;
username: string;
username?: string;
name?: string;
language?: string;
status: TUserStatus;
Expand All @@ -30,18 +30,4 @@ export interface ILoggedUser {
requirePasswordChange?: boolean;
}

export interface ILoggedUserResultFromServer extends Omit<
ILoggedUser,
'enableMessageParserEarlyAdoption' | 'showMessageInMainThread'
> {
settings: IUserSettings;
}

export interface ILoginResultFromServer {
status: string;
authToken: string;
userId: string;
me: ILoggedUserResultFromServer;
}

export type TLoggedUserModel = ILoggedUser & Model;
12 changes: 12 additions & 0 deletions app/definitions/ILoginCredentials.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
export type {
ICredentialsAppleAPI,
ICredentialsAuthenticated,
ICredentialsCasAPI,
ICredentialsCrowdAPI,
ICredentialsLdapAPI,
ICredentialsOAuth,
ICredentialsPasswordAPI,
ICredentialsSamlAPI,
ICredentialsTotpAPI,
ILoginCredentials
} from '@rocket.chat/sdk/interfaces';
2 changes: 1 addition & 1 deletion app/definitions/IProfile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { type ReactNode } from 'react';
export interface IProfileParams {
realname?: string;
name?: string;
username: string;
username?: string;
email: string | null;
newPassword: string;
currentPassword: string;
Expand Down
2 changes: 1 addition & 1 deletion app/definitions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export * from './ERoomType';
export * from './IAttachment';
export * from './ICannedResponse';
export * from './ICertificate';
export * from './ICredentials';
export * from './ILoginCredentials';
export * from './IEmoji';
export * from './ILivechatDepartment';
export * from './ILivechatTag';
Expand Down
3 changes: 3 additions & 0 deletions app/lib/hooks/useUserData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ const useUserData = (rid: string) => {
const result = await getUserInfo(rid);
if (result.success) {
const { user } = result;
if (!user.username) {
return;
}
const username = useRealName && user.name ? user.name : user.username;
setUser({
username,
Expand Down
4 changes: 2 additions & 2 deletions app/lib/methods/helpers/events.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { type ICredentials } from '../../../definitions';
import { type ILoginCredentials } from '../../../definitions';
import { type IEmitUserInteraction } from '../../../containers/UIKit/interfaces';
import log from './log';

Expand All @@ -13,7 +13,7 @@ type TEventEmitterEmmitArgs =
| { visible: boolean; onCancel?: null | Function }
| { cancel: () => void }
| { submit: (param: string) => void }
| { params: ICredentials }
| { params: ILoginCredentials }
| IEmitUserInteraction;

class EventEmitter {
Expand Down
6 changes: 3 additions & 3 deletions app/lib/methods/helpers/isReadOnly.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { store as reduxStore } from '../../store/auxStore';
import { type ISubscription } from '../../../definitions';
import { hasPermission } from './helpers';

const canPostReadOnly = async (room: Partial<ISubscription>, username: string) => {
const canPostReadOnly = async (room: Partial<ISubscription>, username?: string) => {
// RC 6.4.0
const isUnmuted = !!room?.unmuted?.find(m => m === username);
// TODO: this is not reactive. If this permission changes, the component won't be updated
Expand All @@ -11,10 +11,10 @@ const canPostReadOnly = async (room: Partial<ISubscription>, username: string) =
return permission[0] || isUnmuted;
};

const isMuted = (room: Partial<ISubscription>, username: string) =>
const isMuted = (room: Partial<ISubscription>, username?: string) =>
room && room.muted && room.muted.find && !!room.muted.find(m => m === username);

export const isReadOnly = async (room: Partial<ISubscription>, username: string): Promise<boolean> => {
export const isReadOnly = async (room: Partial<ISubscription>, username?: string): Promise<boolean> => {
if (room.archived) {
return true;
}
Expand Down
7 changes: 2 additions & 5 deletions app/lib/methods/helpers/parseSamlOrCasRedirect.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,8 @@ describe('parseSamlOrCasRedirect', () => {
expect(parseSamlOrCasRedirect('https://server.example/login', 'cas', 'sso-token')).toBeNull();
});

it('passes credentialToken through as undefined when ssoToken is not provided', () => {
expect(parseSamlOrCasRedirect('https://server.example/_cas/validate/xyz', 'cas')).toEqual({
kind: 'cas',
payload: { cas: { credentialToken: undefined } }
});
it('returns null when authType is cas and no ssoToken is provided', () => {
expect(parseSamlOrCasRedirect('https://server.example/_cas/validate/xyz', 'cas')).toBeNull();
});

it('returns null when authType is cas and the URL only has a SAML-style token', () => {
Expand Down
16 changes: 11 additions & 5 deletions app/lib/methods/helpers/parseSamlOrCasRedirect.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,22 @@
import parse from 'url-parse';

import { type ICredentials } from '../../../definitions';
import { type ICredentialsCasAPI, type ICredentialsSamlAPI } from '../../../definitions';

export type SamlOrCasRedirect = { kind: 'saml'; payload: ICredentials } | { kind: 'cas'; payload: ICredentials } | null;
export type SamlOrCasRedirect =
| { kind: 'saml'; payload: ICredentialsSamlAPI }
| { kind: 'cas'; payload: ICredentialsCasAPI }
| null;

export const parseSamlOrCasRedirect = (url: string, authType: string, ssoToken?: string): SamlOrCasRedirect => {
const parsedUrl = parse(url, true);
if (authType === 'saml' && parsedUrl.query?.saml_idp_credentialToken) {
const token = parsedUrl.query.saml_idp_credentialToken || ssoToken;
return { kind: 'saml', payload: { credentialToken: token, saml: true } };
const samlCredentialToken = parsedUrl.query?.saml_idp_credentialToken;
if (authType === 'saml' && samlCredentialToken) {
return { kind: 'saml', payload: { credentialToken: samlCredentialToken, saml: true } };
}
if (authType === 'cas' && (parsedUrl.pathname?.includes('validate') || parsedUrl.query?.ticket)) {
if (!ssoToken) {
return null;
}
return { kind: 'cas', payload: { cas: { credentialToken: ssoToken } } };
}
return null;
Expand Down
23 changes: 12 additions & 11 deletions app/lib/methods/logout.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import database, { getDatabase } from '../database';
import log from './helpers/log';
import { disconnect } from '../services/connect';
import sdk from '../services/sdk';
import { toSdkCredentials } from '../services/toSdkCredentials';
import { CURRENT_SERVER, E2E_PRIVATE_KEY, E2E_PUBLIC_KEY, E2E_RANDOM_PASSWORD_KEY, TOKEN_KEY } from '../constants/keys';
import UserPreferences from './userPreferences';
import { removePushToken } from '../services/restApi';
Expand Down Expand Up @@ -67,18 +66,20 @@ export async function removeServer({ server }: { server: string }): Promise<void
if (userId) {
const resume = UserPreferences.getString(`${TOKEN_KEY}-${userId}`);

try {
const sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl: isSsl(server) });
await sdk.login(toSdkCredentials({ resume: resume ?? undefined }));
if (resume) {
try {
const sdk = new RocketchatClient({ host: server, protocol: 'ddp', useSsl: isSsl(server) });
await sdk.login({ resume });

const token = getDeviceToken();
if (token) {
await sdk.del('push.token', { token });
}
const token = getDeviceToken();
if (token) {
await sdk.del('push.token', { token });
}

await sdk.logout();
} catch (e) {
log(e);
await sdk.logout();
} catch (e) {
log(e);
}
}
}

Expand Down
Loading
Loading