| 143 | * Migration utility to help transition from manual token management to provider-based auth |
| 144 | */ |
| 145 | export function useAuthMigration() { |
| 146 | const { token: providerToken, isAuthenticated } = useAuth(); |
| 147 | const { token: storeToken, clear: clearStore } = useAuthStore(); |
| 148 | |
| 149 | useEffect(() => { |
| 150 | // If user has a manually set token in store but no provider auth, |
| 151 | // we might need to migrate them |
| 152 | if (storeToken && !isAuthenticated && !providerToken) { |
| 153 | console.info( |
| 154 | 'Found existing token in store. You may need to sign in with the new auth system to continue.', |
| 155 | ); |
| 156 | |
| 157 | // Optionally, you could attempt to validate the existing token |
| 158 | // or prompt the user to sign in again |
| 159 | } |
| 160 | }, [storeToken, isAuthenticated, providerToken]); |
| 161 | |
| 162 | const migrateToProviderAuth = () => { |
| 163 | // Clear the old auth data and redirect to sign in |
| 164 | clearStore(); |
| 165 | // This will trigger the auth flow |
| 166 | }; |
| 167 | |
| 168 | return { |
| 169 | needsMigration: !!storeToken && !isAuthenticated, |
| 170 | migrateToProviderAuth, |
| 171 | }; |
| 172 | } |