From 71c1ebc2133b3f9c55912d31269a5a0fb634b19f Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Wed, 9 Sep 2020 18:29:59 +0300 Subject: [PATCH] Migration: let the server know that we are migrating an account Needed for automatic email confirmation. --- src/MigrateV2.tsx | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/MigrateV2.tsx b/src/MigrateV2.tsx index 759e14b..775b9a5 100644 --- a/src/MigrateV2.tsx +++ b/src/MigrateV2.tsx @@ -4,6 +4,7 @@ import * as React from "react"; import * as EteSync from "etesync"; import * as Etebase from "etebase"; +import URI from "urijs"; import Button from "@material-ui/core/Button"; import TextField from "@material-ui/core/TextField"; import Switch from "@material-ui/core/Switch"; @@ -44,7 +45,7 @@ export default function MigrateV2(props: PropsType) { const [etebase, setEtebase] = React.useState(); const wizardPages = [ - (props: PagePropsType) => ( + (pageProps: PagePropsType) => ( <>

Etebase 2.0 Migration tool

@@ -53,7 +54,7 @@ export default function MigrateV2(props: PropsType) { The migration doesn't delete any data. It only copies your data over to the new EteSync 2.0 server. This means that there is no risk of data-loss in the migration.

- + ), (pageProps: PagePropsType) => ( @@ -161,6 +162,21 @@ export function WizardAccountPage(props: OurPagePropsType & { setEtebase: (eteba username, email, }; + // Let the server know the account is asking for a migration + { + const serviceUrl = URI(props.etesync.serviceApiUrl).normalize(); + serviceUrl.segment("etesync-v2"); + serviceUrl.segment("confirm-migration"); + serviceUrl.segment(""); + const response = await fetch(serviceUrl.normalize().toString(), { + method: "post", + headers: { Authorization: "Token " + props.etesync.credentials.authToken }, + }); + if (!response.ok) { + throw new Error("Failed preparing account for migration"); + } + } + etebase = await Etebase.Account.signup(user, password, serverUrl); } props.setEtebase(etebase);