···139139 )
140140 const newAgent = new AtpAgent({ service: newPdsUrl })
141141 const newHostDesc = await newAgent.com.atproto.server.describeServer()
142142+142143 if (this.createNewAccount) {
143143- const newHostWebDid = newHostDesc.data.did
144144+ let needToCreateANewAccount = true
145145+ //check to see if repo already exists
146146+ try {
147147+ // If successful at all means the repo is there
148148+ const _ = await newAgent.com.atproto.sync.getRepoStatus({
149149+ did: usersDid,
150150+ })
151151+ needToCreateANewAccount = false
152152+ // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
153153+ this.migrateBlobs = false
154154+ console.log('New check. Repo already exists, logging in')
155155+ } catch (error) {
156156+ //Should be good to cont, just logging in case we need it in the future for troubleshooting
157157+ console.error('Expected Error on RepoStatus check.', error)
158158+ }
144159145145- safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS')
160160+ if (needToCreateANewAccount) {
161161+ const newHostWebDid = newHostDesc.data.did
146162147147- const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
148148- aud: newHostWebDid,
149149- lxm: 'com.atproto.server.createAccount',
150150- })
151151- const serviceJwt = createAuthResp.data.token
163163+ safeStatusUpdate(statusUpdateHandler, 'Creating a new account on the new PDS')
152164153153- let createAccountRequest = {
154154- did: usersDid,
155155- handle: newHandle,
156156- email: newEmail,
157157- password: password,
158158- }
159159- if (inviteCode) {
160160- createAccountRequest.inviteCode = inviteCode
161161- }
162162- if (verificationCode) {
163163- createAccountRequest.verificationCode = verificationCode
164164- }
165165- try {
166166- const createNewAccount = await newAgent.com.atproto.server.createAccount(
167167- createAccountRequest,
168168- {
169169- headers: { authorization: `Bearer ${serviceJwt}` },
170170- encoding: 'application/json',
171171- },
172172- )
165165+ const createAuthResp = await oldAgent.com.atproto.server.getServiceAuth({
166166+ aud: newHostWebDid,
167167+ lxm: 'com.atproto.server.createAccount',
168168+ })
169169+ const serviceJwt = createAuthResp.data.token
173170174174- if (createNewAccount.data.did !== usersDid.toString()) {
175175- throw new Error('Did not create the new account with the same did as the old account')
171171+ let createAccountRequest = {
172172+ did: usersDid,
173173+ handle: newHandle,
174174+ email: newEmail,
175175+ password: password,
176176 }
177177- } catch (error) {
178178- // Ideally should catch if the repo already exists, and if so silently log it and move along to the next step
179179- if (error?.error === 'AlreadyExists') {
180180- // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
181181- this.migrateBlobs = false
182182- console.log('Repo already exists, logging in')
183183- } else {
184184- // Catches any other error and stops the migration process
185185- throw error
177177+ if (inviteCode) {
178178+ createAccountRequest.inviteCode = inviteCode
179179+ }
180180+ if (verificationCode) {
181181+ createAccountRequest.verificationCode = verificationCode
182182+ }
183183+ try {
184184+ const createNewAccount = await newAgent.com.atproto.server.createAccount(
185185+ createAccountRequest,
186186+ {
187187+ headers: { authorization: `Bearer ${serviceJwt}` },
188188+ encoding: 'application/json',
189189+ },
190190+ )
191191+192192+ if (createNewAccount.data.did !== usersDid.toString()) {
193193+ throw new Error('Did not create the new account with the same did as the old account')
194194+ }
195195+ } catch (error) {
196196+ // Ideally should catch if the repo already exists, and if so silently log it and move along to the next step
197197+ if (error?.error === 'AlreadyExists') {
198198+ // Sets the migrate blobs flag to false so it moves on to just migrate missing blobs in the event of a retry
199199+ this.migrateBlobs = false
200200+ console.log('Repo already exists, logging in')
201201+ } else {
202202+ // Catches any other error and stops the migration process
203203+ throw error
204204+ }
186205 }
187206 }
188207 }
208208+189209 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account')
190210191211 await newAgent.login({
···408408 {#if errorMessage !== null}
409409 <div class="error-message">{errorMessage}</div>
410410411411- <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>
411411+ <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>
412412413413 {/if}
414414