|
1 | 1 | import { images } from "@/constants/images"; |
| 2 | +import { identifyPostHogUser } from "@/lib/analytics"; |
| 3 | +import { useLanguageStore } from "@/store/UseLanguageStore"; |
2 | 4 | import { useAuth, useSignIn, useSignUp, useSSO } from "@clerk/expo"; |
3 | 5 | import { |
4 | 6 | AntDesign, |
@@ -121,8 +123,9 @@ export function AuthScreen({ mode }: AuthScreenProps) { |
121 | 123 | const { signIn, fetchStatus: signInStatus } = useSignIn(); |
122 | 124 | const { signUp, fetchStatus: signUpStatus } = useSignUp(); |
123 | 125 | const { startSSOFlow } = useSSO(); |
124 | | - const { userId } = useAuth(); |
| 126 | + const { userId: authUserId } = useAuth(); |
125 | 127 | const posthog = usePostHog(); |
| 128 | + const selectedLanguageId = useLanguageStore((state) => state.selectedLanguageId); |
126 | 129 | const [emailAddress, setEmailAddress] = useState(""); |
127 | 130 | const [password, setPassword] = useState(""); |
128 | 131 | const [authError, setAuthError] = useState<string | null>(null); |
@@ -230,10 +233,12 @@ export function AuthScreen({ mode }: AuthScreenProps) { |
230 | 233 | return; |
231 | 234 | } |
232 | 235 |
|
233 | | - const userId = signUp.createdUserId; |
234 | | - if (userId) { |
235 | | - posthog.identify(userId, { |
236 | | - $set_once: { sign_up_date: new Date().toISOString() }, |
| 236 | + const newUserId = signUp.createdUserId; |
| 237 | + if (newUserId) { |
| 238 | + identifyPostHogUser({ |
| 239 | + isSignUp: true, |
| 240 | + preferredLanguageId: selectedLanguageId, |
| 241 | + userId: newUserId, |
237 | 242 | }); |
238 | 243 | } |
239 | 244 | posthog.capture("sign_up_completed"); |
@@ -261,9 +266,12 @@ export function AuthScreen({ mode }: AuthScreenProps) { |
261 | 266 | return; |
262 | 267 | } |
263 | 268 |
|
264 | | - const userId = getStableUserId(signIn); |
265 | | - if (userId) { |
266 | | - posthog.identify(userId); |
| 269 | + const signedInUserId = getStableUserId(signIn); |
| 270 | + if (signedInUserId) { |
| 271 | + identifyPostHogUser({ |
| 272 | + preferredLanguageId: selectedLanguageId, |
| 273 | + userId: signedInUserId, |
| 274 | + }); |
267 | 275 | } |
268 | 276 | posthog.capture("sign_in_completed"); |
269 | 277 | } |
@@ -310,8 +318,15 @@ export function AuthScreen({ mode }: AuthScreenProps) { |
310 | 318 |
|
311 | 319 | if (sessionId) { |
312 | 320 | await setActive?.({ session: sessionId }); |
313 | | - if (userId) { |
314 | | - posthog.identify(userId); |
| 321 | + const completedUserId = |
| 322 | + getStableUserId(ssoSignUp) ?? getStableUserId(ssoSignIn) ?? authUserId; |
| 323 | + |
| 324 | + if (completedUserId) { |
| 325 | + identifyPostHogUser({ |
| 326 | + isSignUp: Boolean(ssoSignUp?.createdUserId), |
| 327 | + preferredLanguageId: selectedLanguageId, |
| 328 | + userId: completedUserId, |
| 329 | + }); |
315 | 330 | } |
316 | 331 | posthog.capture("social_auth_completed", { strategy, auth_mode: mode }); |
317 | 332 | router.replace("/"); |
|
0 commit comments