Skip to content

Commit

Permalink
fix: don't always redirect iOS PWA to sign-in page
Browse files Browse the repository at this point in the history
  • Loading branch information
th0rgall committed Oct 6, 2023
1 parent 5c40b33 commit 4ba45af
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 10 additions & 0 deletions src/lib/api/auth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import type { Garden } from '../types/Garden';
import type { User as FirebaseUser } from 'firebase/auth';
import { trackEvent } from '$lib/util';
import { PlausibleEvent } from '$lib/types/Plausible';
import { isOnIDevicePWA } from './push-registrations';

// These are not Svelte stores, because we do not wish to listen to updates on them.
// They are abstracted away by the User store, and trigger updates on that store.
Expand Down Expand Up @@ -202,6 +203,15 @@ export const createAuthObserver = (): Unsubscribe => {
routeTo = routes.SIGN_IN;
}
}

// If we're logged out, on an iDevice PWA, and opening the homepage
// then immediately redirect away from the homepage and skip to the
// sign-in screen (we assume the user has already seen the homepage)
// This gives it a more app-like feel.
if (getCurrentRoute()?.route === '/' && isOnIDevicePWA()) {
routeTo = routes.SIGN_IN;
}

// If we know we are logged out, we are not loading anymore.
isUserLoading.set(false);
}
Expand Down
5 changes: 0 additions & 5 deletions src/routes/+layout.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
} from '$lib/api/push-registrations';
import { NOTIFICATION_PROMPT_DISMISSED_COOKIE } from '$lib/constants';
import { resetPushRegistrationStores } from '$lib/stores/pushRegistrations';
import { goto } from '$lib/util/navigate';
type MaybeUnsubscriberFunc = (() => void) | undefined;
Expand Down Expand Up @@ -163,10 +162,6 @@
if (!unsubscribeFromAuthObserver) {
unsubscribeFromAuthObserver = createAuthObserver();
}
if (isOnIDevicePWA()) {
goto(routes.SIGN_IN);
}
vh = `${window.innerHeight * 0.01}px`;
});
Expand Down

0 comments on commit 4ba45af

Please sign in to comment.