feat: get and pass accounts token
This commit is contained in:
parent
688c840af6
commit
5b1eb3df9b
2 changed files with 16 additions and 16 deletions
|
@ -3,7 +3,7 @@ import EnteSpinner from '@ente/shared/components/EnteSpinner';
|
|||
import { ACCOUNTS_PAGES } from '@ente/shared/constants/pages';
|
||||
import HTTPService from '@ente/shared/network/HTTPService';
|
||||
import { logError } from '@ente/shared/sentry';
|
||||
import { LS_KEYS, setData } from '@ente/shared/storage/localStorage';
|
||||
import { LS_KEYS, getData, setData } from '@ente/shared/storage/localStorage';
|
||||
import { useRouter } from 'next/router';
|
||||
import { useEffect } from 'react';
|
||||
|
||||
|
@ -12,14 +12,7 @@ const AccountHandoff = () => {
|
|||
|
||||
const retrieveAccountData = () => {
|
||||
try {
|
||||
// get the data from the fragment
|
||||
const fragment = window.location.hash.substring(1);
|
||||
|
||||
const stringified = window.atob(fragment);
|
||||
|
||||
const deserialized = JSON.parse(stringified);
|
||||
|
||||
setData(LS_KEYS.USER, deserialized);
|
||||
extractAccountsToken();
|
||||
|
||||
router.push(ACCOUNTS_PAGES.PASSKEYS);
|
||||
} catch (e) {
|
||||
|
@ -38,6 +31,19 @@ const AccountHandoff = () => {
|
|||
});
|
||||
};
|
||||
|
||||
const extractAccountsToken = () => {
|
||||
const urlParams = new URLSearchParams(window.location.search);
|
||||
const token = urlParams.get('token');
|
||||
if (!token) {
|
||||
throw new Error('token not found');
|
||||
}
|
||||
|
||||
let user = getData(LS_KEYS.USER) || {};
|
||||
user.token = token;
|
||||
|
||||
setData(LS_KEYS.USER, user);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
getClientPackageName();
|
||||
retrieveAccountData();
|
||||
|
|
|
@ -15,7 +15,6 @@ 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';
|
||||
|
@ -73,17 +72,12 @@ export default function UtilitySection({ closeSidebar }) {
|
|||
closeSidebar();
|
||||
|
||||
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);
|
||||
|
||||
const accountsToken = await getAccountsToken();
|
||||
|
||||
window.location.href = `${getAccountsURL()}${ACCOUNTS_PAGES.ACCOUNT_HANDOFF
|
||||
}?package=${CLIENT_PACKAGE_NAMES.get(
|
||||
APPS.PHOTOS
|
||||
)}&jwtToken=${accountsToken}#${serializedB64}`;
|
||||
)}&token=${accountsToken}`;
|
||||
} catch (e) {
|
||||
logError(e, 'failed to redirect to accounts page');
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue