···81 safeStatusUpdate(statusUpdateHandler, 'Resolving old PDS')
82 let { usersDid: didFromLookUp, pds: oldPds } = await handleAndPDSResolver(oldHandle)
83 usersDid = didFromLookUp
84- // usersDid = await handleResolver.resolve(oldHandle)
85- // const didDoc = await docResolver.resolve(usersDid)
86- // safeStatusUpdate(
87- // statusUpdateHandler,
88- // 'Resolving did document and finding your current PDS URL',
89- // )
90-91- // let oldPds
92- // try {
93- // oldPds = didDoc.service.filter(s => s.type === 'AtprotoPersonalDataServer')[0]
94- // .serviceEndpoint
95- // } catch (error) {
96- // console.error(error)
97- // throw new Error('Could not find a PDS in the DID document.')
98- // }
99100 oldAgent = new AtpAgent({
101 service: oldPds,
···143 if (verificationCode) {
144 createAccountRequest.verificationCode = verificationCode
145 }
146- const createNewAccount = await newAgent.com.atproto.server.createAccount(
147- createAccountRequest,
148- {
149- headers: { authorization: `Bearer ${serviceJwt}` },
150- encoding: 'application/json',
151- },
152- )
0153154- if (createNewAccount.data.did !== usersDid.toString()) {
155- throw new Error('Did not create the new account with the same did as the old account')
000000000156 }
157 }
158 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account')
···81 safeStatusUpdate(statusUpdateHandler, 'Resolving old PDS')
82 let { usersDid: didFromLookUp, pds: oldPds } = await handleAndPDSResolver(oldHandle)
83 usersDid = didFromLookUp
0000000000000008485 oldAgent = new AtpAgent({
86 service: oldPds,
···128 if (verificationCode) {
129 createAccountRequest.verificationCode = verificationCode
130 }
131+ try {
132+ const createNewAccount = await newAgent.com.atproto.server.createAccount(
133+ createAccountRequest,
134+ {
135+ headers: { authorization: `Bearer ${serviceJwt}` },
136+ encoding: 'application/json',
137+ },
138+ )
139140+ if (createNewAccount.data.did !== usersDid.toString()) {
141+ throw new Error('Did not create the new account with the same did as the old account')
142+ }
143+ } catch (error) {
144+ // Ideally should catch if the repo already exists, and if so silently log it and move along to the next step
145+ if (error?.error === 'AlreadyExists') {
146+ console.log('Repo already exists, logging in')
147+ } else {
148+ // Catches any other error and stops the migration process
149+ throw error
150+ }
151 }
152 }
153 safeStatusUpdate(statusUpdateHandler, 'Logging in with the new account')