diff --git a/src/libs/Reauthentication.ts b/src/libs/Reauthentication.ts index 47cbc45f3f0..3a4fffbeb27 100644 --- a/src/libs/Reauthentication.ts +++ b/src/libs/Reauthentication.ts @@ -140,10 +140,9 @@ function reauthenticate(command = ''): Promise { // Prevent reauthentication if credentials are missing (e.g. after sign out) if (!credentials?.autoGeneratedLogin || !credentials?.autoGeneratedPassword) { Log.info('[Reauthenticate] No credentials available, redirecting to sign in'); - // The following lines are commented out to test if it's the cause of #fireroom-2026-01-28-user-signout - // setIsAuthenticating(false); - // redirectToSignIn('No credentials available'); - // return false; + setIsAuthenticating(false); + redirectToSignIn('No credentials available'); + return false; } Log.info(`[Reauthenticate] Re-authenticating with ${shouldUseNewPartnerName ? 'new' : 'old'} partner name`); diff --git a/tests/actions/SessionTest.ts b/tests/actions/SessionTest.ts index de12c9cc820..c72354545a7 100644 --- a/tests/actions/SessionTest.ts +++ b/tests/actions/SessionTest.ts @@ -16,6 +16,7 @@ import {setHasRadio} from '@libs/NetworkState'; import PushNotification from '@libs/Notification/PushNotification'; // This lib needs to be imported, but it has nothing to export since all it contains is an Onyx connection import '@libs/Notification/PushNotification/subscribeToPushNotifications'; +import reauthenticate from '@libs/Reauthentication'; import CONFIG from '@src/CONFIG'; import CONST from '@src/CONST'; import * as SessionUtil from '@src/libs/actions/Session'; @@ -62,6 +63,22 @@ beforeEach(() => { }); describe('Session', () => { + test('reauthenticate redirects to sign in with "No credentials available" when credentials are missing', async () => { + // Given no signed-in user — beforeEach calls Onyx.clear(), so NetworkStore's credentials are null + + const redirectToSignInSpy = jest.spyOn(SignInRedirect, 'default').mockImplementation(() => Promise.resolve()); + + // When reauthenticate is called with no credentials stored + const result = await reauthenticate('TestCommand'); + await waitForBatchedUpdates(); + + // Then it should redirect to sign in instead of attempting to call Authenticate with undefined credentials + expect(result).toBe(false); + expect(redirectToSignInSpy).toHaveBeenCalledWith('No credentials available'); + + redirectToSignInSpy.mockRestore(); + }); + test('Authenticate is called with saved credentials when a session expires', async () => { // Given a test user and set of authToken with subscriptions to session and credentials const TEST_USER_LOGIN = 'test@testguy.com';