@@ -37,6 +37,7 @@ import type {
3737import {
3838 addAccount ,
3939 authGitHub ,
40+ getAccountUUID ,
4041 getToken ,
4142 hasAccounts ,
4243 refreshAccount ,
@@ -142,6 +143,14 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
142143 unsubscribeNotification,
143144 } = useNotifications ( ) ;
144145
146+ const persistAuth = useCallback (
147+ ( nextAuth : AuthState ) => {
148+ setAuth ( nextAuth ) ;
149+ saveState ( { auth : nextAuth , settings } ) ;
150+ } ,
151+ [ settings ] ,
152+ ) ;
153+
145154 const refreshAllAccounts = useCallback ( async ( ) => {
146155 if ( ! auth . accounts . length ) {
147156 return ;
@@ -155,9 +164,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
155164 accounts : refreshedAccounts ,
156165 } ;
157166
158- setAuth ( updatedAuth ) ;
159- saveState ( { auth : updatedAuth , settings } ) ;
160- } , [ auth , settings ] ) ;
167+ persistAuth ( updatedAuth ) ;
168+ } , [ auth , persistAuth ] ) ;
161169
162170 // TODO - Remove migration logic in future release
163171 const migrateAuthTokens = useCallback ( async ( ) => {
@@ -173,9 +181,18 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
173181 } ) ,
174182 ) ;
175183
176- const tokensMigrated = migratedAccounts . some (
177- ( account , index ) => account . token !== auth . accounts [ index ] ?. token ,
178- ) ;
184+ const tokensMigrated = migratedAccounts . some ( ( migratedAccount ) => {
185+ const originalAccount = auth . accounts . find (
186+ ( account ) =>
187+ getAccountUUID ( account ) === getAccountUUID ( migratedAccount ) ,
188+ ) ;
189+
190+ if ( ! originalAccount ) {
191+ return true ;
192+ }
193+
194+ return migratedAccount . token !== originalAccount . token ;
195+ } ) ;
179196
180197 if ( ! tokensMigrated ) {
181198 return ;
@@ -185,9 +202,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
185202 accounts : migratedAccounts ,
186203 } ;
187204
188- setAuth ( updatedAuth ) ;
189- saveState ( { auth : updatedAuth , settings } ) ;
190- } , [ auth , settings ] ) ;
205+ persistAuth ( updatedAuth ) ;
206+ } , [ auth , persistAuth ] ) ;
191207
192208 // biome-ignore lint/correctness/useExhaustiveDependencies: Fetch new notifications when account count or filters change
193209 useEffect ( ( ) => {
@@ -364,9 +380,8 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
364380
365381 const updatedAuth = await addAccount ( auth , 'GitHub App' , token , hostname ) ;
366382
367- setAuth ( updatedAuth ) ;
368- saveState ( { auth : updatedAuth , settings } ) ;
369- } , [ auth , settings ] ) ;
383+ persistAuth ( updatedAuth ) ;
384+ } , [ auth , persistAuth ] ) ;
370385
371386 const loginWithOAuthApp = useCallback (
372387 async ( data : LoginOAuthAppOptions ) => {
@@ -375,10 +390,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
375390
376391 const updatedAuth = await addAccount ( auth , 'OAuth App' , token , hostname ) ;
377392
378- setAuth ( updatedAuth ) ;
379- saveState ( { auth : updatedAuth , settings } ) ;
393+ persistAuth ( updatedAuth ) ;
380394 } ,
381- [ auth , settings ] ,
395+ [ auth , persistAuth ] ,
382396 ) ;
383397
384398 const loginWithPersonalAccessToken = useCallback (
@@ -393,10 +407,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
393407 hostname ,
394408 ) ;
395409
396- setAuth ( updatedAuth ) ;
397- saveState ( { auth : updatedAuth , settings } ) ;
410+ persistAuth ( updatedAuth ) ;
398411 } ,
399- [ auth , settings ] ,
412+ [ auth , persistAuth ] ,
400413 ) ;
401414
402415 const logoutFromAccount = useCallback (
@@ -405,10 +418,9 @@ export const AppProvider = ({ children }: { children: ReactNode }) => {
405418
406419 const updatedAuth = removeAccount ( auth , account ) ;
407420
408- setAuth ( updatedAuth ) ;
409- saveState ( { auth : updatedAuth , settings } ) ;
421+ persistAuth ( updatedAuth ) ;
410422 } ,
411- [ auth , settings , removeAccountNotifications ] ,
423+ [ auth , removeAccountNotifications , persistAuth ] ,
412424 ) ;
413425
414426 const fetchNotificationsWithAccounts = useCallback (
0 commit comments