@@ -5,6 +5,7 @@ import type React from 'react';
55import { useCallback , useEffect , useRef , useState } from 'react' ;
66import type ReactGoogleRecaptcha from 'react-google-recaptcha' ;
77import type { RenderingTarget } from '../types/renderingTarget' ;
8+ import { getNewslettersClient } from './bridgetApi' ;
89import { lazyFetchEmailWithTimeout } from './fetchEmail' ;
910import {
1011 getEffectiveMarketingOptIn ,
@@ -305,18 +306,38 @@ export const useNewsletterSignupForm = (
305306 useEffect ( ( ) => {
306307 setCaptchaSiteKey ( window . guardian . config . page . googleRecaptchaSiteKey ) ;
307308 } , [ ] ) ;
309+
308310 useEffect ( ( ) => {
309- if ( emailFetchStartedRef . current ) return ;
310- if ( isSignedIn === 'Pending' ) return ;
311- emailFetchStartedRef . current = true ;
312-
313- void resolveUserEmail ( isSignedIn ) . then ( ( email ) => {
314- if ( ! isString ( email ) ) return ;
315- setUserEmail ( email ) ;
316- setHasPrefilledEmail ( true ) ;
317- setIsInteracted ( true ) ;
318- } ) ;
319- } , [ isSignedIn ] ) ;
311+ if ( renderingTarget === 'Apps' ) {
312+ // Fill in email using apps bridget API
313+ void getNewslettersClient ( )
314+ . getLoggedInUserEmail ( )
315+ . then ( ( maybeEmail ) => {
316+ const email = maybeEmail . emailAddress ;
317+ if ( ! email ) return ;
318+ setUserEmail ( email ) ;
319+ setHasPrefilledEmail ( true ) ;
320+ setIsInteracted ( true ) ;
321+ } )
322+ . catch ( ( reason ) => {
323+ console . log (
324+ 'Failed to getLoggedInUserEmail from bridget ' ,
325+ reason ,
326+ ) ;
327+ } ) ;
328+ } else {
329+ if ( emailFetchStartedRef . current ) return ;
330+ if ( isSignedIn === 'Pending' ) return ;
331+ emailFetchStartedRef . current = true ;
332+
333+ void resolveUserEmail ( isSignedIn ) . then ( ( email ) => {
334+ if ( ! isString ( email ) ) return ;
335+ setUserEmail ( email ) ;
336+ setHasPrefilledEmail ( true ) ;
337+ setIsInteracted ( true ) ;
338+ } ) ;
339+ }
340+ } , [ isSignedIn , renderingTarget ] ) ;
320341
321342 const submitForm = useCallback (
322343 async ( emailAddress : string , token : string ) : Promise < void > => {
0 commit comments