MCPcopy Index your code
hub / github.com/bytebase/bytebase / migrateUserStorage

Function migrateUserStorage

frontend/src/utils/storage-migrate.ts:194–215  ·  view source on GitHub ↗
(oldEmail: string, newEmail: string)

Source from the content-addressed store, hash-verified

192 * Renames all keys ending with `.{oldEmail}` to end with `.{newEmail}`.
193 */
194export function migrateUserStorage(oldEmail: string, newEmail: string) {
195 if (!oldEmail || !newEmail || oldEmail === newEmail) return;
196
197 const suffix = `.${oldEmail}`;
198 const keysToMigrate: string[] = [];
199
200 for (let i = 0; i < localStorage.length; i++) {
201 const key = localStorage.key(i);
202 if (key?.endsWith(suffix)) {
203 keysToMigrate.push(key);
204 }
205 }
206
207 for (const key of keysToMigrate) {
208 const newKey = key.slice(0, -suffix.length) + `.${newEmail}`;
209 const value = localStorage.getItem(key);
210 if (value !== null) {
211 localStorage.setItem(newKey, value);
212 localStorage.removeItem(key);
213 }
214 }
215}

Callers 2

ProfilePageFunction · 0.90

Calls 1

keyMethod · 0.45

Tested by

no test coverage detected