MCPcopy Create free account
hub / github.com/dailydotdev/apps / AuthContextProvider

Function AuthContextProvider

packages/shared/src/contexts/AuthContext.tsx:166–295  ·  view source on GitHub ↗
({
  children,
  user,
  updateUser,
  isFetched,
  loadingUser,
  tokenRefreshed,
  hasValidCachedToken,
  cachedTokenWasInvalid,
  loadedUserFromCache,
  getRedirectUri,
  refetchBoot,
  visit,
  accessToken,
  squads,
  feeds,
  firstLoad,
  geo,
  isAndroidApp,
}: AuthContextProviderProps)

Source from the content-addressed store, hash-verified

164>;
165
166export const AuthContextProvider = ({
167 children,
168 user,
169 updateUser,
170 isFetched,
171 loadingUser,
172 tokenRefreshed,
173 hasValidCachedToken,
174 cachedTokenWasInvalid,
175 loadedUserFromCache,
176 getRedirectUri,
177 refetchBoot,
178 visit,
179 accessToken,
180 squads,
181 feeds,
182 firstLoad,
183 geo,
184 isAndroidApp,
185}: AuthContextProviderProps): ReactElement => {
186 const [loginState, setLoginState] = useState<LoginState | null>(null);
187 const endUser = user && 'providers' in user ? user : null;
188 const referral = user?.referralId || user?.referrer;
189 const referralOrigin = user?.referralOrigin;
190 const router = useRouter();
191 const isFunnelRef = useRef(!!router?.pathname?.startsWith(webFunnelPrefix));
192 const isValidRegion = useMemo(
193 () => !invalidPlusRegions.includes(geo?.region),
194 [geo?.region],
195 );
196 const growthbook = useGrowthBook();
197 // Before boot, wait until the flags and route params that feed query keys
198 // are built from have settled, or the feed would be requested twice
199 const isCachedSessionReady =
200 !!hasValidCachedToken && !!growthbook?.ready && !!router?.isReady;
201 const isTokenValid = tokenRefreshed || isCachedSessionReady;
202 const isAuthReady = !isNullOrUndefined(firstLoad);
203
204 const showLogin = useCallback(
205 ({ trigger, options = {} }) => {
206 const hasCompanion = !!isCompanionActivated();
207 if (hasCompanion) {
208 const signup = `${process.env.NEXT_PUBLIC_WEBAPP_URL}signup?close=true`;
209 window.open(signup);
210 return;
211 }
212
213 setLoginState({ ...options, trigger });
214
215 if (!isExtension) {
216 return;
217 }
218
219 const params = new URLSearchParams(globalThis?.location.search);
220 params.delete(AFTER_AUTH_PARAM);
221
222 router.push(`${onboardingUrl}?${params.toString()}`);
223 },

Callers

nothing calls this directly

Calls 5

isNullOrUndefinedFunction · 0.90
isCompanionActivatedFunction · 0.90
checkIfGdprCoveredFunction · 0.85
pushMethod · 0.80
useRouterFunction · 0.50

Tested by

no test coverage detected