Skip to content

Commit

Permalink
Merge pull request #39608 from bernhardoj/fix/39075-sign-in-button-st…
Browse files Browse the repository at this point in the history
…ill-shows-after-login

Fix sign in button remains when login new user via public room
  • Loading branch information
iwiznia authored Apr 5, 2024
2 parents c82ec7e + 18bc7b4 commit ebc59d1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ import * as Session from '@userActions/Session';
import CONST from '@src/CONST';
import ONYXKEYS from '@src/ONYXKEYS';
import ROUTES from '@src/ROUTES';
import type {Policy} from '@src/types/onyx';
import type {Policy, Session as SessionType} from '@src/types/onyx';

type TopBarOnyxProps = {
policy: OnyxEntry<Policy>;
session: OnyxEntry<Pick<SessionType, 'authTokenType'>>;
};

// eslint-disable-next-line react/no-unused-prop-types
type TopBarProps = {activeWorkspaceID?: string} & TopBarOnyxProps;

function TopBar({policy}: TopBarProps) {
function TopBar({policy, session}: TopBarProps) {
const styles = useThemeStyles();
const theme = useTheme();
const {translate} = useLocalize();
const isAnonymousUser = Session.isAnonymousUser(session);

const headerBreadcrumb = policy?.name
? {type: CONST.BREADCRUMB_TYPE.STRONG, text: policy.name}
Expand Down Expand Up @@ -57,7 +59,7 @@ function TopBar({policy}: TopBarProps) {
/>
</View>
</View>
{Session.isAnonymousUser() ? (
{isAnonymousUser ? (
<SignInButton />
) : (
<Tooltip text={translate('common.search')}>
Expand All @@ -84,4 +86,8 @@ export default withOnyx<TopBarProps, TopBarOnyxProps>({
policy: {
key: ({activeWorkspaceID}) => `${ONYXKEYS.COLLECTION.POLICY}${activeWorkspaceID}`,
},
session: {
key: ONYXKEYS.SESSION,
selector: (session) => session && {authTokenType: session.authTokenType},
},
})(TopBar);
6 changes: 3 additions & 3 deletions src/libs/actions/Session/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import throttle from 'lodash/throttle';
import type {ChannelAuthorizationData} from 'pusher-js/types/src/core/auth/options';
import type {ChannelAuthorizationCallback} from 'pusher-js/with-encryption';
import {InteractionManager, Linking, NativeModules} from 'react-native';
import type {OnyxUpdate} from 'react-native-onyx';
import type {OnyxEntry, OnyxUpdate} from 'react-native-onyx';
import Onyx from 'react-native-onyx';
import type {ValueOf} from 'type-fest';
import * as PersistedRequests from '@libs/actions/PersistedRequests';
Expand Down Expand Up @@ -175,8 +175,8 @@ function signOut() {
/**
* Checks if the account is an anonymous account.
*/
function isAnonymousUser(): boolean {
return session.authTokenType === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
function isAnonymousUser(sessionParam?: OnyxEntry<Session>): boolean {
return (sessionParam?.authTokenType ?? session.authTokenType) === CONST.AUTH_TOKEN_TYPES.ANONYMOUS;
}

function hasStashedSession(): boolean {
Expand Down

0 comments on commit ebc59d1

Please sign in to comment.