feat: get accounts token and pass to passkeys url
This commit is contained in:
parent
ad1fab8edb
commit
688c840af6
2 changed files with 54 additions and 25 deletions
|
@ -14,11 +14,13 @@ import { AppContext } from 'pages/_app';
|
|||
import { APPS, CLIENT_PACKAGE_NAMES } from '@ente/shared/apps/constants';
|
||||
import ThemeSwitcher from '@ente/shared/components/ThemeSwitcher';
|
||||
import { getAccountsURL } from '@ente/shared/network/api';
|
||||
import { logError } from '@ente/shared/sentry';
|
||||
import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
|
||||
import { THEME_COLOR } from '@ente/shared/themes/constants';
|
||||
import { EnteMenuItem } from 'components/Menu/EnteMenuItem';
|
||||
import WatchFolder from 'components/WatchFolder';
|
||||
import isElectron from 'is-electron';
|
||||
import { getAccountsToken } from 'services/userService';
|
||||
import { getDownloadAppMessage } from 'utils/ui';
|
||||
import { isInternalUser } from 'utils/user';
|
||||
import Preferences from './Preferences';
|
||||
|
@ -67,16 +69,24 @@ export default function UtilitySection({ closeSidebar }) {
|
|||
router.push(PAGES.CHANGE_EMAIL);
|
||||
};
|
||||
|
||||
const redirectToAccountsPage = () => {
|
||||
const redirectToAccountsPage = async () => {
|
||||
closeSidebar();
|
||||
|
||||
// serialize the user data to pass it over to accounts
|
||||
const userData = getData(LS_KEYS.USER);
|
||||
const serialized = JSON.stringify(userData);
|
||||
const serializedB64 = window.btoa(serialized);
|
||||
try {
|
||||
// serialize the user data to pass it over to accounts
|
||||
const userData = getData(LS_KEYS.USER);
|
||||
const serialized = JSON.stringify(userData);
|
||||
const serializedB64 = window.btoa(serialized);
|
||||
|
||||
window.location.href = `${getAccountsURL()}${ACCOUNTS_PAGES.ACCOUNT_HANDOFF
|
||||
}?package=${CLIENT_PACKAGE_NAMES.get(APPS.PHOTOS)}#${serializedB64}`;
|
||||
const accountsToken = await getAccountsToken();
|
||||
|
||||
window.location.href = `${getAccountsURL()}${ACCOUNTS_PAGES.ACCOUNT_HANDOFF
|
||||
}?package=${CLIENT_PACKAGE_NAMES.get(
|
||||
APPS.PHOTOS
|
||||
)}&jwtToken=${accountsToken}#${serializedB64}`;
|
||||
} catch (e) {
|
||||
logError(e, 'failed to redirect to accounts page');
|
||||
}
|
||||
};
|
||||
|
||||
const redirectToDeduplicatePage = () => router.push(PAGES.DEDUPLICATE);
|
||||
|
|
|
@ -1,26 +1,28 @@
|
|||
import { putAttributes } from '@ente/accounts/api/user';
|
||||
import { logoutUser } from '@ente/accounts/services/user';
|
||||
import { getRecoveryKey } from '@ente/shared/crypto/helpers';
|
||||
import { ApiError } from '@ente/shared/error';
|
||||
import HTTPService from '@ente/shared/network/HTTPService';
|
||||
import {
|
||||
getEndpoint,
|
||||
getFamilyPortalURL,
|
||||
isDevDeployment,
|
||||
} from '@ente/shared/network/api';
|
||||
import { getData, LS_KEYS } from '@ente/shared/storage/localStorage';
|
||||
import localForage from '@ente/shared/storage/localForage';
|
||||
import { getToken } from '@ente/shared/storage/localStorage/helpers';
|
||||
import HTTPService from '@ente/shared/network/HTTPService';
|
||||
import { getRecoveryKey } from '@ente/shared/crypto/helpers';
|
||||
import { logError } from '@ente/shared/sentry';
|
||||
import localForage from '@ente/shared/storage/localForage';
|
||||
import { LS_KEYS, getData } from '@ente/shared/storage/localStorage';
|
||||
import {
|
||||
UserDetails,
|
||||
DeleteChallengeResponse,
|
||||
GetRemoteStoreValueResponse,
|
||||
GetFeatureFlagResponse,
|
||||
} from 'types/user';
|
||||
import { ApiError } from '@ente/shared/error';
|
||||
import { getLocalFamilyData, isPartOfFamily } from 'utils/user/family';
|
||||
getToken,
|
||||
setLocalMapEnabled,
|
||||
} from '@ente/shared/storage/localStorage/helpers';
|
||||
import { AxiosResponse, HttpStatusCode } from 'axios';
|
||||
import { setLocalMapEnabled } from '@ente/shared/storage/localStorage/helpers';
|
||||
import { putAttributes } from '@ente/accounts/api/user';
|
||||
import { logoutUser } from '@ente/accounts/services/user';
|
||||
import {
|
||||
DeleteChallengeResponse,
|
||||
GetFeatureFlagResponse,
|
||||
GetRemoteStoreValueResponse,
|
||||
UserDetails,
|
||||
} from 'types/user';
|
||||
import { getLocalFamilyData, isPartOfFamily } from 'utils/user/family';
|
||||
|
||||
const ENDPOINT = getEndpoint();
|
||||
|
||||
|
@ -70,6 +72,24 @@ export const getFamiliesToken = async () => {
|
|||
}
|
||||
};
|
||||
|
||||
export const getAccountsToken = async () => {
|
||||
try {
|
||||
const token = getToken();
|
||||
|
||||
const resp = await HTTPService.get(
|
||||
`${ENDPOINT}/users/accounts-token`,
|
||||
null,
|
||||
{
|
||||
'X-Auth-Token': token,
|
||||
}
|
||||
);
|
||||
return resp.data['accountsToken'];
|
||||
} catch (e) {
|
||||
logError(e, 'failed to get accounts token');
|
||||
throw e;
|
||||
}
|
||||
};
|
||||
|
||||
export const getRoadmapRedirectURL = async () => {
|
||||
try {
|
||||
const token = getToken();
|
||||
|
@ -165,9 +185,8 @@ export const getFamilyPortalRedirectURL = async () => {
|
|||
try {
|
||||
const jwtToken = await getFamiliesToken();
|
||||
const isFamilyCreated = isPartOfFamily(getLocalFamilyData());
|
||||
return `${getFamilyPortalURL()}?token=${jwtToken}&isFamilyCreated=${isFamilyCreated}&redirectURL=${
|
||||
window.location.origin
|
||||
}/gallery`;
|
||||
return `${getFamilyPortalURL()}?token=${jwtToken}&isFamilyCreated=${isFamilyCreated}&redirectURL=${window.location.origin
|
||||
}/gallery`;
|
||||
} catch (e) {
|
||||
logError(e, 'unable to generate to family portal URL');
|
||||
throw e;
|
||||
|
|
Loading…
Add table
Reference in a new issue