routes fix

extensive loging added
This commit is contained in:
dimitar committed 2026-03-10 02:22:11 +01:00
1 parent 36315ea5cf
commit 22c274bb83
9 files changed
+1252 -508

No files matched your search

+99 -1
View File
@@ -2,12 +2,26 @@ import { ClerkProvider, ClerkLoaded } from "@clerk/clerk-expo";
import { Stack } from "expo-router";
import * as SecureStore from "expo-secure-store";
import { View, Text } from "react-native";
import { useEffect, useState } from "react";
console.log("========================================");
console.log("🚀 _layout.tsx loaded at:", new Date().toISOString());
console.log(
"📦 EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY:",
process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY,
);
console.log("========================================");
// Token cache for Clerk
const tokenCache = {
async getToken(key: string) {
try {
return SecureStore.getItemAsync(key);
const value = await SecureStore.getItemAsync(key);
console.log(`[TokenCache] Getting key: ${key}, exists: ${!!value}`);
if (value && value.length > 50) {
console.log(`[TokenCache] Value preview: ${value.substring(0, 50)}...`);
}
return value;
} catch (err) {
console.error("Error getting token:", err);
return null;
@@ -15,6 +29,10 @@ const tokenCache = {
},
async saveToken(key: string, value: string) {
try {
console.log(`[TokenCache] Saving key: ${key}`);
if (value && value.length > 50) {
console.log(`[TokenCache] Value preview: ${value.substring(0, 50)}...`);
}
return SecureStore.setItemAsync(key, value);
} catch (err) {
console.error("Error saving token:", err);
@@ -24,8 +42,71 @@ const tokenCache = {
export default function RootLayout() {
const publishableKey = process.env.EXPO_PUBLIC_CLERK_PUBLISHABLE_KEY;
const [cacheCleared, setCacheCleared] = useState(false);
console.log(
"🔑 [RootLayout] Component rendering with publishableKey:",
publishableKey,
);
// TEMPORARY: Clear Clerk cache on app start to fix instance mismatch
useEffect(() => {
console.log("⚡ [RootLayout] useEffect triggered - starting cache cleanup");
const clearOldClerkCache = async () => {
try {
console.log("🔍 [RootLayout] Checking for old Clerk tokens...");
const keysToCheck = [
"__clerk_client_jwt",
"__clerk_db_jwt",
"__clerk_client_uat",
"__clerk_session_id",
"__clerk_refresh_token",
"__clerk_session_jwt",
];
for (const key of keysToCheck) {
try {
const value = await SecureStore.getItemAsync(key);
if (value) {
console.log(`📌 [RootLayout] Found token at ${key}`);
console.log(
`📝 [RootLayout] Token preview: ${value.substring(0, 80)}...`,
);
// Check if it's from the old instance
if (value.includes("pleasing-pheasant-20")) {
console.log(`🗑️ [RootLayout] DELETING old token from ${key}`);
await SecureStore.deleteItemAsync(key);
} else if (value.includes("needed-elephant-64")) {
console.log(
`✅ [RootLayout] Token is from correct instance (needed-elephant-64)`,
);
} else {
console.log(
`⚠️ [RootLayout] Token doesn't match known instances`,
);
}
}
} catch (e) {
console.log(`❌ [RootLayout] Error checking key ${key}:`, e);
}
}
console.log("✅ [RootLayout] Old token cleanup complete");
setCacheCleared(true);
} catch (error) {
console.error("❌ [RootLayout] Error clearing old cache:", error);
setCacheCleared(true); // Continue anyway
}
};
clearOldClerkCache();
}, []);
if (!publishableKey) {
console.log("❌ [RootLayout] No publishable key found!");
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Missing Clerk Publishable Key</Text>
@@ -38,6 +119,23 @@ export default function RootLayout() {
);
}
if (!cacheCleared) {
console.log("⏳ [RootLayout] Waiting for cache to clear...");
return (
<View style={{ flex: 1, justifyContent: "center", alignItems: "center" }}>
<Text>Clearing old authentication cache...</Text>
<Text style={{ marginTop: 8, fontSize: 12, color: "#666" }}>
Check the terminal for logs...
</Text>
</View>
);
}
console.log(
"🚀 [RootLayout] Rendering ClerkProvider with key:",
publishableKey?.substring(0, 20) + "...",
);
return (
<ClerkProvider tokenCache={tokenCache} publishableKey={publishableKey}>
<ClerkLoaded>