feat(mobile): consent-gate i auth-flödet
This commit is contained in:
@@ -1,12 +1,14 @@
|
|||||||
import { Redirect, Tabs } from "expo-router";
|
import { Redirect, Tabs } from "expo-router";
|
||||||
import { Text } from "react-native";
|
import { Text } from "react-native";
|
||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { api } from "@/lib/api";
|
import { api, getConsent, type ConsentStatus } from "@/lib/api";
|
||||||
import { persistLanguageTag, useAuth } from "@/lib/auth";
|
import { persistLanguageTag, useAuth } from "@/lib/auth";
|
||||||
import { colors } from "@/lib/theme";
|
import { colors } from "@/lib/theme";
|
||||||
import { getLanguageTag, t } from "@/lib/i18n";
|
import { getLanguageTag, t } from "@/lib/i18n";
|
||||||
import { setMeasurementSystem, setUnitLanguage } from "@/lib/units";
|
import { setMeasurementSystem, setUnitLanguage } from "@/lib/units";
|
||||||
|
import { ConsentScreen } from "@/components/ConsentScreen";
|
||||||
import type { MeasurementSystem } from "@app/shared-types";
|
import type { MeasurementSystem } from "@app/shared-types";
|
||||||
|
import { TERMS_VERSION } from "@app/shared-types";
|
||||||
|
|
||||||
function TabIcon({ glyph, focused }: { glyph: string; focused: boolean }) {
|
function TabIcon({ glyph, focused }: { glyph: string; focused: boolean }) {
|
||||||
return <Text style={{ fontSize: 22, opacity: focused ? 1 : 0.45 }}>{glyph}</Text>;
|
return <Text style={{ fontSize: 22, opacity: focused ? 1 : 0.45 }}>{glyph}</Text>;
|
||||||
@@ -39,7 +41,18 @@ export default function TabsLayout() {
|
|||||||
const onboardingStep = useAuth((s) => s.onboardingStep);
|
const onboardingStep = useAuth((s) => s.onboardingStep);
|
||||||
useApplyLocalePreferences(Boolean(accessToken));
|
useApplyLocalePreferences(Boolean(accessToken));
|
||||||
|
|
||||||
|
const { data: consent, isLoading: consentLoading } = useQuery<ConsentStatus>({
|
||||||
|
queryKey: ["consent"],
|
||||||
|
queryFn: getConsent,
|
||||||
|
enabled: Boolean(accessToken),
|
||||||
|
staleTime: 60_000,
|
||||||
|
});
|
||||||
|
|
||||||
if (!accessToken) return <Redirect href="/(auth)/login" />;
|
if (!accessToken) return <Redirect href="/(auth)/login" />;
|
||||||
|
if (consentLoading) return null;
|
||||||
|
if (!consent?.accepted || consent.version !== TERMS_VERSION) {
|
||||||
|
return <ConsentScreen onAccepted={() => {}} />;
|
||||||
|
}
|
||||||
// Progressive onboarding (FAS 1b): only block if step A not done
|
// Progressive onboarding (FAS 1b): only block if step A not done
|
||||||
if (!onboardingCompleted && onboardingStep === "a") return <Redirect href="/onboarding" />;
|
if (!onboardingCompleted && onboardingStep === "a") return <Redirect href="/onboarding" />;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user