Skip to content

Commit

Permalink
Merge pull request #4455 from mozilla/fix-always-logged-in-mpp-3644
Browse files Browse the repository at this point in the history
MPP-3644: Update more uses of `useIsLoggedIn`
  • Loading branch information
jwhitlock authored Feb 29, 2024
2 parents d9780cd + 64ce79a commit 8513199
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 9 deletions.
2 changes: 1 addition & 1 deletion frontend/src/components/layout/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const Layout = (props: Props) => {
? l10n.getString("logo-alt")
: l10n.getString("logo-premium-alt");

const homePath = isLoggedIn ? "/accounts/profile" : "/";
const homePath = isLoggedIn === "logged-in" ? "/accounts/profile" : "/";

const handleToggle = () => {
setMobileMenuExpanded(!mobileMenuExpanded);
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/components/layout/topmessage/NpsSurvey.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const NpsSurvey = () => {
const gaEvent = useGaEvent();

const hasBeenUserForThreeDays =
isLoggedIn &&
isLoggedIn === "logged-in" &&
firstSeen instanceof Date &&
Date.now() - firstSeen.getTime() > 3 * 24 * 60 * 60;

Expand Down
2 changes: 1 addition & 1 deletion frontend/src/hooks/firstSeen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export function useFirstSeen(): Date | null {
const isLoggedIn = useIsLoggedIn();
const profileData = useProfiles();

if (!isLoggedIn || !profileData.data?.[0].id) {
if (!(isLoggedIn === "logged-in") || !profileData.data?.[0].id) {
return null;
}

Expand Down
6 changes: 1 addition & 5 deletions frontend/src/hooks/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,7 @@ export type LoggedInState = "logged-out" | "logged-in" | "unknown";
*/
export function useIsLoggedIn(): LoggedInState {
const profileData = useProfiles();
const checking =
typeof profileData === "undefined" ||
(typeof profileData.data === "undefined" &&
typeof profileData.error === "undefined");
if (checking) {
if (profileData.isLoading) {
return "unknown";
}
return typeof profileData !== "undefined" &&
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/pages/_app.page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ function MyApp({ Component, pageProps }: AppProps) {
// and read by the add-on.
// Capitalised boolean for backwards compatibility;
// this element was previously generated by Django:
data-user-logged-in={isLoggedIn ? "True" : "False"}
data-user-logged-in={isLoggedIn === "logged-in" ? "True" : "False"}
></firefox-private-relay-addon>
<OverlayProvider id="overlayProvider">
<Component {...pageProps} />
Expand Down

0 comments on commit 8513199

Please sign in to comment.