Skip to content
Open
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
5 changes: 2 additions & 3 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,6 @@ const App = (props: AppProps): JSX.Element => {

const { isDialogOpen } = useActionDialog();
const isOpen = isDialogOpen(ActionDialog.ModifyStorage);
const token = localStorageService.get(LocalStorageItem.UserToken);
const newToken = localStorageService.get(LocalStorageItem.NewToken);
const params = new URLSearchParams(window.location.search);
const isVpnAuth = params.get('vpnAuth') === 'true';
Expand Down Expand Up @@ -107,11 +106,11 @@ const App = (props: AppProps): JSX.Element => {
}
}, [params]);

if ((token && skipSignupIfLoggedIn) || (token && navigationService.history.location.pathname !== '/new')) {
if ((newToken && skipSignupIfLoggedIn) || (newToken && navigationService.history.location.pathname !== '/new')) {
/**
* In case we receive a valid redirectUrl param, we return to that URL with the current token
*/
const redirectUrl = authService.getRedirectUrl(params, token);
const redirectUrl = authService.getRedirectUrl(params, newToken);

if (redirectUrl) {
window.location.replace(redirectUrl);
Expand Down
2 changes: 1 addition & 1 deletion src/app/core/plugins/axios.plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const axiosPlugin: AppPlugin = {

axios.interceptors.request.use((requestConfig) => {
const tokenByWorkspace: { [key in Workspace]: string } = {
[Workspace.Individuals]: localStorageService.get(LocalStorageItem.UserToken) || '',
[Workspace.Individuals]: localStorageService.get(LocalStorageItem.NewToken) || '',
[Workspace.Business]: localStorageService.get(LocalStorageItem.TeamToken) || '',
};

Expand Down
5 changes: 0 additions & 5 deletions src/app/core/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,14 +133,9 @@ export enum LocalStorageItem {
Workspace = 'workspace',
User = 'xUser',
UserMnemonic = 'xMnemonic',
UserToken = 'xToken',
Team = 'xTeam',
TeamToken = 'xTokenTeam',
NewToken = 'xNewToken',
Language = 'language',
ShowSummerBanner = 'showSummerBanner',
InvitedToken = 'xInvitedToken',
ResourcesToken = 'xResourcesToken',
}

export enum OrderDirection {
Expand Down
7 changes: 3 additions & 4 deletions src/app/store/slices/user/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ export const initializeUserThunk = createAsyncThunk<
export const refreshUserThunk = createAsyncThunk<void, { forceRefresh?: boolean } | undefined, { state: RootState }>(
'user/refresh',
async ({ forceRefresh } = {}, { dispatch, getState }) => {
const userToken = localStorageService.get(LocalStorageItem.UserToken);
const userToken = localStorageService.get(LocalStorageItem.NewToken);
const isExpired = isTokenExpired(userToken);

const currentUser = getState().user.user;
Expand Down Expand Up @@ -185,15 +185,14 @@ const updateUserEmailCredentialsThunk = createAsyncThunk<
{ state: RootState }
>('user/updateUser', async (payload, { dispatch, getState }) => {
const currentUser = getState().user.user as UserSettings;
const { newUserData, token, newToken } = payload;
const { newUserData, newToken } = payload;

const user = {
...currentUser,
email: newUserData.email,
bridgeUser: newUserData.email,
username: newUserData.email,
};
localStorageService.set(LocalStorageItem.UserToken, token);
localStorageService.set(LocalStorageItem.NewToken, newToken);
dispatch(userActions.setUser(user));
});
Expand All @@ -219,7 +218,7 @@ export const userSlice = createSlice({
localStorageService.set(LocalStorageItem.User, JSON.stringify(action.payload));
},
setToken: (state: UserState, action: PayloadAction<string>) => {
localStorageService.set(LocalStorageItem.UserToken, action.payload);
localStorageService.set(LocalStorageItem.NewToken, action.payload);
},
resetState: (state: UserState) => {
Object.assign(state, initialState);
Expand Down
5 changes: 0 additions & 5 deletions src/services/auth.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,6 @@ describe('logIn', () => {
};

expect(result).toEqual({
token: mockToken,
newToken: mockNewToken,
user: mockClearUser,
mnemonic: mockMnemonic,
Expand All @@ -252,7 +251,6 @@ describe('logIn', () => {
const mockToken = 'test-token';
const mockNewToken = 'test-new-token';
const mockLoginType = 'web';

const mockPassword = 'password123';
const mockMnemonic =
'until bonus summer risk chunk oyster census ability frown win pull steel measure employ rigid improve riot remind system earn inch broken chalk clip';
Expand Down Expand Up @@ -329,7 +327,6 @@ describe('logIn', () => {
};

expect(result).toEqual({
token: mockToken,
newToken: mockNewToken,
user: mockClearUser,
mnemonic: mockMnemonic,
Expand Down Expand Up @@ -410,7 +407,6 @@ describe('signUp', () => {
expect(spy).toBeCalledWith(mockClearUser);

expect(result).toEqual({
token: mockToken,
newToken: mockNewToken,
user: {
...mockUser,
Expand Down Expand Up @@ -520,7 +516,6 @@ describe('signUp', () => {
expect(spy).toBeCalledWith(mockClearUser);

expect(result).toEqual({
token: mockToken,
newToken: mockNewToken,
user: {
...mockUser,
Expand Down
19 changes: 7 additions & 12 deletions src/services/auth.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ import vpnAuthService from './vpnAuth.service';

type ProfileInfo = {
user: UserSettings;
token: string;
newToken: string;
mnemonic: string;
};
Expand Down Expand Up @@ -180,7 +179,7 @@ export const doLogin = async (
return authClient
.login(loginDetails, cryptoProvider)
.then(async (data) => {
const { user, token, newToken } = data;
const { user, newToken } = data;

const { privateKey: encryptedPrivateKey } = user;

Expand Down Expand Up @@ -211,13 +210,11 @@ export const doLogin = async (
},
};

localStorageService.set(LocalStorageItem.UserToken, token);
localStorageService.set(LocalStorageItem.UserMnemonic, clearMnemonic);
localStorageService.set(LocalStorageItem.NewToken, newToken);

return {
user: clearUser,
token: token,
newToken,
mnemonic: clearMnemonic,
};
Expand Down Expand Up @@ -417,8 +414,7 @@ export const changePassword = async (newPassword: string, currentPassword: strin
encryptVersion: StorageTypes.EncryptionVersion.Aes03,
})
.then((res) => {
const { token, newToken } = res;
if (token) localStorageService.set(LocalStorageItem.UserToken, token);
const { newToken } = res;
if (newToken) localStorageService.set(LocalStorageItem.NewToken, newToken);
})
.catch((error) => {
Expand Down Expand Up @@ -554,12 +550,11 @@ export const unblockAccount = (token: string): Promise<void> => {

export const signUp = async (params: SignUpParams) => {
const { doSignUp, email, password, token, redeemCodeObject, dispatch } = params;
const { xUser, xToken, xNewToken, mnemonic } = await doSignUp(email, password, token);
const { xUser, xNewToken, mnemonic } = await doSignUp(email, password, token);

localStorageService.clear();

localStorageService.set(LocalStorageItem.UserToken, xToken);
localStorageService.set(LocalStorageItem.UserMnemonic , mnemonic);
localStorageService.set(LocalStorageItem.UserMnemonic, mnemonic);
localStorageService.set(LocalStorageItem.NewToken, xNewToken);

const { publicKey, privateKey, publicKyberKey, privateKyberKey } = parseAndDecryptUserKeys(xUser, password);
Expand Down Expand Up @@ -587,12 +582,12 @@ export const signUp = async (params: SignUpParams) => {
await trackSignUp(xUser.uuid);
trackLead(xUser.email, xUser.userId);

return { token: xToken, user: xUser, mnemonic, newToken: xNewToken };
return { user: xUser, mnemonic, newToken: xNewToken };
};

export const logIn = async (params: LogInParams): Promise<ProfileInfo> => {
const { email, password, twoFactorCode, dispatch, loginType = 'web' } = params;
const { token, newToken, user, mnemonic } = await doLogin(email, password, twoFactorCode, loginType);
const { newToken, user, mnemonic } = await doLogin(email, password, twoFactorCode, loginType);
dispatch(userActions.setUser(user));

try {
Expand All @@ -609,7 +604,7 @@ export const logIn = async (params: LogInParams): Promise<ProfileInfo> => {

userActions.setUser(user);

return { token, user, mnemonic, newToken };
return { user, mnemonic, newToken };
};

export const authenticateUser = async (params: AuthenticateUserParams): Promise<ProfileInfo> => {
Expand Down
6 changes: 0 additions & 6 deletions src/services/local-storage.service.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -331,20 +331,14 @@ describe('Testing the local storage service', () => {
});
});


describe('Clearing local storage', () => {
it('When clear storage is requested, then removes all keys', () => {
const expectedKeysToRemove = [
LocalStorageItem.User,
LocalStorageItem.UserMnemonic,
LocalStorageItem.UserToken,
LocalStorageItem.NewToken,
LocalStorageItem.TeamToken,
LocalStorageItem.Workspace,
LocalStorageItem.Language,
LocalStorageItem.ShowSummerBanner,
LocalStorageItem.InvitedToken,
LocalStorageItem.ResourcesToken,
STORAGE_KEYS.B2B_WORKSPACE,
STORAGE_KEYS.WORKSPACE_CREDENTIALS,
...Object.values(STORAGE_KEYS.THEMES),
Expand Down
6 changes: 1 addition & 5 deletions src/views/Login/UniversalLinkSuccessView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,15 @@ export default function UniversalLinkView(): JSX.Element {
}, [user]);

const getUniversalLinkAuthUrl = (user: UserSettings) => {
const token = localStorageService.get(LocalStorageItem.UserToken);
const newToken = localStorageService.get(LocalStorageItem.NewToken);
if (!token) return AppView.Login;
if (!newToken) return AppView.Login;

let baseURL = DEEPLINK_SUCCESS_REDIRECT_BASE;
if (redirectUri) {
baseURL = Buffer.from(redirectUri, 'base64').toString();
}

return `${baseURL}?mnemonic=${btoa(user.mnemonic)}&token=${btoa(token)}&newToken=${btoa(
newToken,
)}&privateKey=${btoa(user.privateKey)}`;
return `${baseURL}?mnemonic=${btoa(user.mnemonic)}&newToken=${btoa(newToken)}&privateKey=${btoa(user.privateKey)}`;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should remove all token related logic in mobile also before merge this

};

// Should redirect to login in the useEffect
Expand Down
13 changes: 8 additions & 5 deletions src/views/Login/components/LogIn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,13 @@ export default function LogIn(): JSX.Element {
}
};

const handleSuccessfulAuth = (token: string, user: UserSettings, mnemonic: string): void => {
const handleSuccessfulAuth = (user: UserSettings, mnemonic: string): void => {
const newToken = localStorageService.get(LocalStorageItem.NewToken);

if (isOAuthFlow && newToken) {
if (!newToken) {
throw new Error('No authentication token available');
}
if (isOAuthFlow) {
const success = handleOAuthSuccess(user, newToken);
if (!success) {
setIsLoggingIn(false);
Expand All @@ -162,7 +165,7 @@ export default function LogIn(): JSX.Element {
return;
}

const redirectUrl = authService.getRedirectUrl(urlParams, token);
const redirectUrl = authService.getRedirectUrl(urlParams, newToken);

if (redirectUrl && !isUniversalLinkMode && !isSharingInvitation) {
globalThis.location.replace(redirectUrl);
Expand Down Expand Up @@ -195,8 +198,8 @@ export default function LogIn(): JSX.Element {
loginType,
};

const { token, user, mnemonic } = await authenticateUser(authParams);
handleSuccessfulAuth(token, user, mnemonic);
const { user, mnemonic } = await authenticateUser(authParams);
handleSuccessfulAuth(user, mnemonic);
Comment thread
CandelR marked this conversation as resolved.
} else {
setShowTwoFactor(true);
setLoginError([]);
Expand Down
7 changes: 3 additions & 4 deletions src/views/Signup/components/SignupForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -167,9 +167,9 @@ function SignUpForm(): JSX.Element {
doSignUp: doRegister,
};

const { token: xToken, newToken: xNewToken } = await authenticateUser(authParams);
const { newToken: xNewToken } = await authenticateUser(authParams);

await redirectTheUserAfterRegistration(xToken, xNewToken, redeemCodeObject);
await redirectTheUserAfterRegistration(xNewToken, redeemCodeObject);
} catch (err: unknown) {
handleSubmitError(err);
} finally {
Expand All @@ -195,7 +195,6 @@ function SignUpForm(): JSX.Element {
};

const redirectTheUserAfterRegistration = async (
xToken: string,
xNewToken: string,
redeemCodeObject?: {
code: string;
Expand All @@ -204,7 +203,7 @@ function SignUpForm(): JSX.Element {
) => {
const urlParams = new URLSearchParams(globalThis.location.search);
const isUniversalLinkMode = urlParams.get('universalLink') == 'true';
const redirectUrl = authService.getRedirectUrl(urlParams, xToken);
const redirectUrl = authService.getRedirectUrl(urlParams, xNewToken);
const isVPNAuth = urlParams.get('vpnAuth');

handleVPNAuth(isVPNAuth, xNewToken);
Expand Down
1 change: 0 additions & 1 deletion src/views/Signup/utils/guestSignupOnSubmit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ describe('guestSignupOnSubmit', () => {
'recaptcha-token',
);
expect(localStorageService.clear).toHaveBeenCalled();
expect(localStorageService.set).toHaveBeenCalledWith(LocalStorageItem.UserToken, 'access-token');
expect(localStorageService.set).toHaveBeenCalledWith(LocalStorageItem.UserMnemonic, 'test mnemonic');
expect(localStorageService.set).toHaveBeenCalledWith(LocalStorageItem.NewToken, 'refresh-token');
expect(parseAndDecryptUserKeys).toHaveBeenCalledWith(mockRegistrationResponse.xUser, 'password123');
Expand Down
8 changes: 1 addition & 7 deletions src/views/Signup/utils/guestSignupOnSubmit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,10 @@ export const guestSignupOnSubmit = async ({

try {
const { email, password, token } = formData;
const { xUser, xToken, xNewToken, mnemonic } = await doRegisterPreCreatedUser(
email,
password,
invitationId,
token || '',
);
const { xUser, xNewToken, mnemonic } = await doRegisterPreCreatedUser(email, password, invitationId, token || '');

localStorageService.clear();

localStorageService.set(LocalStorageItem.UserToken, xToken);
localStorageService.set(LocalStorageItem.UserMnemonic, mnemonic);
localStorageService.set(LocalStorageItem.NewToken, xNewToken);

Expand Down
Loading