import * as SecureStore from 'expo-secure-store';

const SESSION_KEY = 'greenlens_session_v3';

export const getAuthToken = async (): Promise<string> => {
  try {
    const raw = await SecureStore.getItemAsync(SESSION_KEY);
    if (raw) {
      const session = JSON.parse(raw);
      if (typeof session?.token === 'string' && session.token) {
        return session.token;
      }
    }
  } catch {}
  // Return 'guest' instead of throwing to allow guest mode
  return 'guest';
};
