Skip to content

Commit d7bc0ac

Browse files
mikepitreclaude
andcommitted
test(expo): give the fixture one home that shows the outcome of a flow, and remove the state line
A verify launch drew a line of JSON above every screen and padded the frame for it, so the native AuthView and UserProfileView never had the whole window. Specs read that line and not what a user sees. A verify launch now shows one of these, each as the root of the window: a spinner while Clerk loads or a launch ticket signs in, an error screen with the reason, AuthView, a custom flow form, the token cache screen, or the home. The home says "Signed out" with a "Sign in" button that opens AuthView in a modal, or shows the UserButton, "Signed in as <email>", the user ID, the session ID, and a "Sign out" button. The email and user ID come from useUser, the session ID from useSession, and the signed-out text from useAuth, so a hook that keeps a stale value stays visible on the home. A pending session reads as signed out. The auth and nativeAuth screens show the spinner until useAuthViewState().isLoaded is true. The custom flow forms return to the home once the session is active, as auth already did, and are centred again. An unknown verifyScreen and a failed environment load show the error screen. The userButton and userProfile launch screens are gone: the UserButton is on the home and the profile opens from it. The token cache screen reads the cache once, when it mounts, and says whether a client token was kept from the last launch. It used to read again after Clerk loaded, and by then a signed-out client has stored a token of its own, so "present" said nothing about the last launch. The fixture still writes its [verify] line to the console. A launch without verify inputs shows the same home as before. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 parent ea2bdaf commit d7bc0ac

6 files changed

Lines changed: 203 additions & 134 deletions

File tree

‎integration/templates/expo-native/App.tsx‎

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,7 @@ function NativeBuildFixture() {
120120

121121
export default function App() {
122122
if (verifyLaunch) {
123-
return (
124-
<VerifyHost
125-
launch={verifyLaunch}
126-
home={<NativeBuildFixture />}
127-
/>
128-
);
123+
return <VerifyHost launch={verifyLaunch} />;
129124
}
130125

131126
return (
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
import { useAuth, useSession, useUser } from '@clerk/expo';
2+
import { AuthView, type AuthViewMode, UserButton } from '@clerk/expo/native';
3+
import { type ReactElement, useState } from 'react';
4+
import { Button, Modal, StyleSheet, Text, View } from 'react-native';
5+
6+
export function Home({ authMode }: { authMode: AuthViewMode }): ReactElement {
7+
const { isSignedIn, signOut } = useAuth();
8+
const { user } = useUser();
9+
const { session } = useSession();
10+
const [isAuthOpen, setIsAuthOpen] = useState(false);
11+
const closeAuth = (): void => setIsAuthOpen(false);
12+
13+
const pending = session?.status === 'pending';
14+
const account = pending ? null : user;
15+
const activeSession = pending ? null : session;
16+
const emailAddress = account?.primaryEmailAddress?.emailAddress;
17+
18+
return (
19+
<View style={styles.home}>
20+
{isSignedIn && <UserButton />}
21+
{(account || activeSession) && (
22+
<View style={styles.summary}>
23+
{account && (
24+
<Text
25+
testID='e2e.auth.signedIn'
26+
style={styles.heading}
27+
>
28+
{emailAddress ? `Signed in as ${emailAddress}` : 'Signed in'}
29+
</Text>
30+
)}
31+
{account && (
32+
<View style={styles.detail}>
33+
<Text style={styles.detailText}>User ID</Text>
34+
<Text
35+
testID='e2e.auth.userId'
36+
style={styles.detailText}
37+
>
38+
{account.id}
39+
</Text>
40+
</View>
41+
)}
42+
{activeSession && (
43+
<View style={styles.detail}>
44+
<Text style={styles.detailText}>Session ID</Text>
45+
<Text
46+
testID='e2e.auth.sessionId'
47+
style={styles.detailText}
48+
>
49+
{activeSession.id}
50+
</Text>
51+
</View>
52+
)}
53+
</View>
54+
)}
55+
{isSignedIn ? (
56+
<Button
57+
testID='e2e.auth.signOut'
58+
title='Sign out'
59+
onPress={() => void signOut()}
60+
/>
61+
) : (
62+
<>
63+
<Text
64+
testID='e2e.auth.signedOut'
65+
style={styles.heading}
66+
>
67+
Signed out
68+
</Text>
69+
<Button
70+
testID='e2e.auth.signIn'
71+
title='Sign in'
72+
onPress={() => setIsAuthOpen(true)}
73+
/>
74+
</>
75+
)}
76+
77+
<Modal
78+
animationType='slide'
79+
visible={isAuthOpen}
80+
presentationStyle='pageSheet'
81+
onRequestClose={closeAuth}
82+
>
83+
<AuthView
84+
mode={authMode}
85+
onDismiss={closeAuth}
86+
/>
87+
</Modal>
88+
</View>
89+
);
90+
}
91+
92+
const styles = StyleSheet.create({
93+
detail: {
94+
flexDirection: 'row',
95+
gap: 4,
96+
},
97+
detailText: {
98+
color: '#6B6B76',
99+
fontSize: 13,
100+
},
101+
heading: {
102+
fontSize: 17,
103+
textAlign: 'center',
104+
},
105+
home: {
106+
alignItems: 'center',
107+
flex: 1,
108+
gap: 24,
109+
justifyContent: 'center',
110+
padding: 24,
111+
},
112+
summary: {
113+
alignItems: 'center',
114+
gap: 4,
115+
},
116+
});

‎integration/templates/expo-native/screens/TokenCache.tsx‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,20 @@ import { styles } from './styles';
88
const clientTokenKey = '__clerk_client_jwt';
99

1010
export function TokenCache(): ReactElement {
11-
const { user } = useUser();
12-
const [stored, setStored] = useState<boolean | null>(null);
11+
const { isLoaded, user } = useUser();
12+
const [keptAtLaunch, setKeptAtLaunch] = useState<boolean | null>(null);
1313

1414
useEffect(() => {
15-
void tokenCache?.getToken(clientTokenKey).then(token => setStored(Boolean(token)));
16-
}, [user?.id]);
15+
void tokenCache?.getToken(clientTokenKey).then(token => setKeptAtLaunch(Boolean(token)));
16+
}, []);
1717

1818
return (
1919
<View style={styles.form}>
2020
<Text style={styles.title}>Token cache</Text>
2121
<Text testID='verify.tokenCache.clientToken'>
22-
{`stored client token: ${stored === null ? 'checking' : stored ? 'present' : 'absent'}`}
22+
{`client token kept from the last launch: ${keptAtLaunch === null ? 'checking' : keptAtLaunch ? 'yes' : 'no'}`}
2323
</Text>
24-
<Text testID='verify.tokenCache.user'>{`user: ${user?.id ?? 'none'}`}</Text>
24+
<Text testID='verify.tokenCache.user'>{`user: ${isLoaded ? (user?.id ?? 'none') : 'loading'}`}</Text>
2525
</View>
2626
);
2727
}

‎integration/templates/expo-native/screens/styles.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ export const styles = StyleSheet.create({
44
form: {
55
flex: 1,
66
gap: 12,
7+
justifyContent: 'center',
78
padding: 24,
89
},
910
input: {

0 commit comments

Comments
 (0)