mirror of
https://github.com/mealie-recipes/mealie.git
synced 2026-05-12 13:03:31 -04:00
fix: make PWA share target functional on Android Chrome (#7468)
Co-authored-by: Zdenek <tvuj-email@example.com> Co-authored-by: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -211,7 +211,7 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useDark, whenever } from "@vueuse/core";
|
||||
import { useDark, useSessionStorage, whenever } from "@vueuse/core";
|
||||
import { useLoggedInState } from "~/composables/use-logged-in-state";
|
||||
import { usePasswordField } from "~/composables/use-passwords";
|
||||
import { alert } from "~/composables/use-toast";
|
||||
@@ -225,6 +225,7 @@ definePageMeta({
|
||||
const isDark = useDark();
|
||||
|
||||
const router = useRouter();
|
||||
const route = useRoute();
|
||||
const i18n = useI18n();
|
||||
const auth = useMealieAuth();
|
||||
const { $appInfo, $axios } = useNuxtApp();
|
||||
@@ -235,6 +236,9 @@ const isFirstLogin = ref(false);
|
||||
const activityPreferences = useUserActivityPreferences();
|
||||
const { getDefaultActivityRoute } = useDefaultActivity();
|
||||
|
||||
// Survives the page reload that happens during OIDC redirect
|
||||
const pendingShareRedirect = useSessionStorage<string | null>("pwa_share_redirect", null);
|
||||
|
||||
useSeoMeta({
|
||||
title: i18n.t("user.login"),
|
||||
});
|
||||
@@ -259,14 +263,29 @@ useAsyncData(useAsyncKey(), async () => {
|
||||
whenever(
|
||||
() => loggedIn.value && groupSlug.value,
|
||||
() => {
|
||||
// First-login setup always takes priority
|
||||
if (!isDemo.value && isFirstLogin.value && auth.user.value?.admin) {
|
||||
router.push("/admin/setup");
|
||||
return;
|
||||
}
|
||||
|
||||
// After login, honour a pending PWA share redirect.
|
||||
// The redirect param can arrive via the URL query string (password login)
|
||||
// or via sessionStorage (OIDC login, where the OIDC provider reload clears
|
||||
// the query string).
|
||||
const redirectFromQuery = route.query.redirect as string | undefined;
|
||||
const redirectTarget = redirectFromQuery ?? pendingShareRedirect.value;
|
||||
if (redirectTarget && redirectTarget.startsWith("/")) {
|
||||
pendingShareRedirect.value = null;
|
||||
router.push(redirectTarget);
|
||||
return;
|
||||
}
|
||||
|
||||
const defaultActivityRoute = getDefaultActivityRoute(
|
||||
activityPreferences.value.defaultActivity,
|
||||
groupSlug.value,
|
||||
);
|
||||
if (!isDemo.value && isFirstLogin.value && auth.user.value?.admin) {
|
||||
router.push("/admin/setup");
|
||||
}
|
||||
else if (defaultActivityRoute) {
|
||||
if (defaultActivityRoute) {
|
||||
router.push(defaultActivityRoute);
|
||||
}
|
||||
else {
|
||||
@@ -316,6 +335,13 @@ async function oidcAuthenticate(callback = false) {
|
||||
oidcLoggingIn.value = false;
|
||||
}
|
||||
else {
|
||||
// Save any pending PWA share redirect before leaving for the OIDC provider.
|
||||
// The OIDC callback reloads the page, which clears the query string, so we
|
||||
// persist the target in sessionStorage and restore it after login.
|
||||
const redirectTarget = route.query.redirect as string | undefined;
|
||||
if (redirectTarget && redirectTarget.startsWith("/")) {
|
||||
pendingShareRedirect.value = redirectTarget;
|
||||
}
|
||||
navigateTo("/api/auth/oauth", { external: true }); // start the redirect process
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user