Effect CommunityEC
Effect Community6mo ago
22 replies
Maks

Issues with React Native (Expo) x Effect-RX x Schema module

Hey everyone.

Having a few issues with React Native (Expo) x Effect-RX x Schema module, been trying to fix for the last few hours:

1. When using Schema module from Effect. Error: Warning: TypeError: right operand of 'instanceof' is not an object I guess smth with metro bundling ??
2. Also, i don't get why although i handled an error with (sessionResult._tag === 'Failure')

I'm still getting an error that crashes the app, which my backend returned, as user wasn't authed. ERROR Warning: AuthServiceError: Invalid session data (data was null after parsing response)
export type AuthState = {
  status: 'authenticated' | 'unauthenticated' | 'loading';
  lastActivity: number;
  sessionInfo?: SessionIdsSchema;
  error?: string;
};

export const authStateRx = Rx.make<AuthState>({
  status: 'loading',
  lastActivity: Date.now(),
  sessionInfo: undefined,
  error: undefined,
}).pipe(Rx.keepAlive);

export const authStateCheckAndUpdateRx = Rx.make((get) => {
  const authState = get(authStateRx);

  if (authState.status === 'loading') {
    const sessionResult = get(sessionQueryRx);

    if (sessionResult._tag === 'Success') {
      get.set(authStateRx, {
        status: 'authenticated',
        sessionInfo: sessionResult.value,
        lastActivity: Date.now(),
        error: undefined,
      });
    } else if (sessionResult._tag === 'Failure') {
      get.set(authStateRx, {
        status: 'unauthenticated',
        sessionInfo: undefined,
        lastActivity: Date.now(),
        error: 'No valid session',
      });
    }
  }

  return authState;
}).pipe(Rx.keepAlive);



My sessionQueryRx: has the following type:

Rx.Rx<Result<SessionIdsSchema, AuthServiceError | HttpApiDecodeError | HttpClientError | ParseError | TimeoutException>>
Screenshot_2025-08-03_at_16.18.24.png
Screenshot_2025-08-03_at_16.40.31.png
Was this page helpful?