11import React , { createContext , useEffect , useMemo , useState } from 'react' ;
22import type { ReactNode } from 'react' ;
33import { Linking } from 'react-native' ;
4- import { hasAuthToken } from '@libs/actions/Session' ;
54import type { Route } from '@src/ROUTES' ;
65
76type InitialUrlContextType = {
87 initialURL : Route | null ;
98 setInitialURL : React . Dispatch < React . SetStateAction < Route | null > > ;
9+ isAuthenticatedAtStartup : boolean ;
10+ setIsAuthenticatedAtStartup : React . Dispatch < React . SetStateAction < boolean > > ;
1011} ;
1112
1213/** Initial url that will be opened when NewDot is embedded into Hybrid App. */
1314const InitialURLContext = createContext < InitialUrlContextType > ( {
1415 initialURL : null ,
1516 setInitialURL : ( ) => { } ,
17+ isAuthenticatedAtStartup : false ,
18+ setIsAuthenticatedAtStartup : ( ) => { } ,
1619} ) ;
1720
1821type InitialURLContextProviderProps = {
@@ -22,7 +25,7 @@ type InitialURLContextProviderProps = {
2225
2326function InitialURLContextProvider ( { children} : InitialURLContextProviderProps ) {
2427 const [ initialURL , setInitialURL ] = useState < Route | null > ( null ) ;
25- const [ isAuthenticatedAtStartup , setIsAuthenticatedAtStartup ] = useState < boolean > ( ) ;
28+ const [ isAuthenticatedAtStartup , setIsAuthenticatedAtStartup ] = useState < boolean > ( false ) ;
2629
2730 useEffect ( ( ) => {
2831 Linking . getInitialURL ( ) . then ( ( initURL ) => {
@@ -33,16 +36,12 @@ function InitialURLContextProvider({children}: InitialURLContextProviderProps) {
3336 } ) ;
3437 } , [ ] ) ;
3538
36- useEffect ( ( ) => {
37- const isAuthenticated = hasAuthToken ( ) ;
38- setIsAuthenticatedAtStartup ( isAuthenticated ) ;
39- } , [ ] ) ;
40-
4139 const initialUrlContext = useMemo (
4240 ( ) => ( {
4341 initialURL,
4442 setInitialURL,
4543 isAuthenticatedAtStartup,
44+ setIsAuthenticatedAtStartup,
4645 } ) ,
4746 [ initialURL , isAuthenticatedAtStartup ] ,
4847 ) ;
0 commit comments