fix: add auth endpoints to server, fix auth bypass and registration
- server/: commit server code for the first time (was untracked)
- POST /auth/signup and /auth/login endpoints now deployed
- GET /v1/billing/summary now verifies user exists in auth_users
(prevents stale JWTs from bypassing auth → fixes empty dashboard)
- app/_layout.tsx: dual-marker install check (SQLite + SecureStore)
to detect fresh installs reliably on Android
- app/auth/login.tsx, signup.tsx: replace Ionicons leaf logo with
actual app icon image (assets/icon.png)
- services/authService.ts: log HTTP status + server message on auth errors
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
118
app/_layout.tsx
Normal file
118
app/_layout.tsx
Normal file
@@ -0,0 +1,118 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import { Stack } from 'expo-router';
|
||||
import { StatusBar } from 'expo-status-bar';
|
||||
import { StripeProvider } from '@stripe/stripe-react-native';
|
||||
import AsyncStorage from '@react-native-async-storage/async-storage';
|
||||
import { AppProvider, useApp } from '../context/AppContext';
|
||||
import { CoachMarksProvider } from '../context/CoachMarksContext';
|
||||
import { CoachMarksOverlay } from '../components/CoachMarksOverlay';
|
||||
import { useColors } from '../constants/Colors';
|
||||
import { AuthService } from '../services/authService';
|
||||
import { initDatabase, AppMetaDb } from '../services/database';
|
||||
import * as SecureStore from 'expo-secure-store';
|
||||
|
||||
type InitialRoute = 'onboarding' | 'auth/login' | '(tabs)';
|
||||
const STRIPE_PUBLISHABLE_KEY = (process.env.EXPO_PUBLIC_STRIPE_PUBLISHABLE_KEY || 'pk_test_mock_key').trim();
|
||||
const SECURE_INSTALL_MARKER = 'greenlens_install_v1';
|
||||
|
||||
const ensureInstallConsistency = async (): Promise<boolean> => {
|
||||
try {
|
||||
const [sqliteMarker, secureMarker] = await Promise.all([
|
||||
Promise.resolve(AppMetaDb.get('install_marker_v2')),
|
||||
SecureStore.getItemAsync(SECURE_INSTALL_MARKER).catch(() => null),
|
||||
]);
|
||||
|
||||
if (sqliteMarker && secureMarker) return false; // Kein Fresh Install
|
||||
|
||||
// Fresh Install: Alles zurücksetzen
|
||||
await AuthService.logout();
|
||||
await AsyncStorage.removeItem('greenlens_show_tour');
|
||||
AppMetaDb.set('install_marker_v2', '1');
|
||||
await SecureStore.setItemAsync(SECURE_INSTALL_MARKER, '1');
|
||||
return true;
|
||||
} catch (error) {
|
||||
console.error('Failed to initialize install marker', error);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
function RootLayoutInner() {
|
||||
const { isDarkMode, colorPalette, signOut } = useApp();
|
||||
const colors = useColors(isDarkMode, colorPalette);
|
||||
const [initialRoute, setInitialRoute] = useState<InitialRoute | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
(async () => {
|
||||
const didResetSessionForFreshInstall = await ensureInstallConsistency();
|
||||
if (didResetSessionForFreshInstall) {
|
||||
await signOut();
|
||||
}
|
||||
const session = await AuthService.getSession();
|
||||
if (!session) {
|
||||
// Kein Benutzer → immer zum Onboarding (Landing + Register/Login)
|
||||
setInitialRoute('auth/login');
|
||||
return;
|
||||
}
|
||||
const validity = await AuthService.validateWithServer();
|
||||
if (validity === 'invalid') {
|
||||
await AuthService.logout();
|
||||
await signOut();
|
||||
setInitialRoute('auth/login');
|
||||
return;
|
||||
}
|
||||
// 'valid' or 'unreachable' (offline) → allow tab navigation
|
||||
setInitialRoute('(tabs)');
|
||||
})();
|
||||
}, [signOut]);
|
||||
|
||||
if (initialRoute === null) return null;
|
||||
|
||||
return (
|
||||
<>
|
||||
<StatusBar style={isDarkMode ? 'light' : 'dark'} />
|
||||
<Stack
|
||||
screenOptions={{
|
||||
headerShown: false,
|
||||
contentStyle: { backgroundColor: colors.background },
|
||||
}}
|
||||
initialRouteName={initialRoute}
|
||||
>
|
||||
<Stack.Screen name="onboarding" options={{ animation: 'none' }} />
|
||||
<Stack.Screen name="auth/login" options={{ animation: 'slide_from_right' }} />
|
||||
<Stack.Screen name="auth/signup" options={{ animation: 'slide_from_right' }} />
|
||||
<Stack.Screen name="(tabs)" options={{ animation: 'none' }} />
|
||||
<Stack.Screen
|
||||
name="scanner"
|
||||
options={{ presentation: 'fullScreenModal', animation: 'slide_from_bottom' }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="plant/[id]"
|
||||
options={{ presentation: 'card', animation: 'slide_from_right' }}
|
||||
/>
|
||||
<Stack.Screen
|
||||
name="lexicon"
|
||||
options={{ presentation: 'fullScreenModal', animation: 'slide_from_bottom' }}
|
||||
/>
|
||||
</Stack>
|
||||
{/* Coach Marks rendern über allem */}
|
||||
<CoachMarksOverlay />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default function RootLayout() {
|
||||
initDatabase();
|
||||
|
||||
return (
|
||||
<StripeProvider
|
||||
publishableKey={STRIPE_PUBLISHABLE_KEY}
|
||||
merchantIdentifier="merchant.com.greenlens"
|
||||
>
|
||||
<AppProvider>
|
||||
<CoachMarksProvider>
|
||||
<RootLayoutInner />
|
||||
</CoachMarksProvider>
|
||||
</AppProvider>
|
||||
</StripeProvider>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user