···139 )
140 const newAgent = new AtpAgent({ service: newPdsUrl })
141 const newHostDesc = await newAgent.com.atproto.server.describeServer()
0142 if (this.createNewAccount) {
143- const newHostWebDid = newHostDesc.data.did
00000000000000144145- safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS')
0146147- const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
148- aud: newHostWebDid,
149- lxm: 'com.atproto.server.createAccount',
150- })
151- const serviceJwt = createAuthResp.data.token
152153- let createAccountRequest = {
154- did: usersDid,
155- handle: newHandle,
156- email: newEmail,
157- password: password,
158- }
159- if (inviteCode) {
160- createAccountRequest.inviteCode = inviteCode
161- }
162- if (verificationCode) {
163- createAccountRequest.verificationCode = verificationCode
164- }
165- try {
166- const createNewAccount = await newAgent.com.atproto.server.createAccount(
167- createAccountRequest,
168- {
169- headers: { authorization: `Bearer ${serviceJwt}` },
170- encoding: 'application/json',
171- },
172- )
173174- if (createNewAccount.data.did !== usersDid.toString()) {
175- throw new Error('Did not create the new account with the same did as the old account')
000176 }
177- } catch (error) {
178- // Ideally should catch if the repo already exists, and if so silently log it and move along to the next step
179- if (error?.error === 'AlreadyExists') {
180- // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
181- this.migrateBlobs = false
182- console.log('Repo already exists, logging in')
183- } else {
184- // Catches any other error and stops the migration process
185- throw error
0000000000000000000186 }
187 }
188 }
0189 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account')
190191 await newAgent.login({
···139 )
140 const newAgent = new AtpAgent({ service: newPdsUrl })
141 const newHostDesc = await newAgent.com.atproto.server.describeServer()
142+143 if (this.createNewAccount) {
144+ let needToCreateANewAccount = true
145+ //check to see if repo already exists
146+ try {
147+ // If successful at all means the repo is there
148+ const _ = await newAgent.com.atproto.sync.getRepoStatus({
149+ did: usersDid,
150+ })
151+ needToCreateANewAccount = false
152+ // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
153+ this.migrateBlobs = false
154+ console.log('New check. Repo already exists, logging in')
155+ } catch (error) {
156+ //Should be good to cont, just logging in case we need it in the future for troubleshooting
157+ console.error('Expected Error on RepoStatus check.', error)
158+ }
159160+ if (needToCreateANewAccount) {
161+ const newHostWebDid = newHostDesc.data.did
162163+ safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS')
0000164165+ const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
166+ aud: newHostWebDid,
167+ lxm: 'com.atproto.server.createAccount',
168+ })
169+ const serviceJwt = createAuthResp.data.token
000000000000000170171+ let createAccountRequest = {
172+ did: usersDid,
173+ handle: newHandle,
174+ email: newEmail,
175+ password: password,
176 }
177+ if (inviteCode) {
178+ createAccountRequest.inviteCode = inviteCode
179+ }
180+ if (verificationCode) {
181+ createAccountRequest.verificationCode = verificationCode
182+ }
183+ try {
184+ const createNewAccount = await newAgent.com.atproto.server.createAccount(
185+ createAccountRequest,
186+ {
187+ headers: { authorization: `Bearer ${serviceJwt}` },
188+ encoding: 'application/json',
189+ },
190+ )
191+192+ if (createNewAccount.data.did !== usersDid.toString()) {
193+ throw new Error('Did not create the new account with the same did as the old account')
194+ }
195+ } catch (error) {
196+ // Ideally should catch if the repo already exists, and if so silently log it and move along to the next step
197+ if (error?.error === 'AlreadyExists') {
198+ // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
199+ this.migrateBlobs = false
200+ console.log('Repo already exists, logging in')
201+ } else {
202+ // Catches any other error and stops the migration process
203+ throw error
204+ }
205 }
206 }
207 }
208+209 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account')
210211 await newAgent.login({
···408 {#if errorMessage !== null}
409 <div class="error-message">{errorMessage}</div>
410411- <div id="status-message" class="status-message">A error has occurred. Please take a screenshot of this screen for support. You can also retry by refreshing the page, it will not harm your account.</div>
412413 {/if}
414
···408 {#if errorMessage !== null}
409 <div class="error-message">{errorMessage}</div>
410411+ <div id="status-message" class="status-message">A error has occurred. Please take a screenshot of this screen for support. You can also retry by refreshing the page and entering the same information as before, it will not harm your account.</div>
412413 {/if}
414