Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

320
Visualizações
Cannot read property 'id' of null From Realm database

I'm getting an error when I want to export a default realm configuration useRealm so that I will be able to use it other files

import Realm from "realm";
import { getRealmApp } from "../functions/realmConfig";
import { ItemSchema } from "./itemSchema";

export const app = getRealmApp();
export const useRealmApp = getRealmApp();

export const user = useRealmApp.currentUser;
export const partitionValue = useRealmApp.currentUser.id;

export const config = {
  schema: [ItemSchema], //other schema will be added in the future
  sync: {
    user: user,
    partitionValue: partitionValue, //app.currentUser.id,
  },
};

export const useRealm = new Realm(config);

expected results is, if the user is not logged in it should show a login screen. But it throws this error and doesn't give me a chance to log in:

index.ts?77fd:9 Uncaught TypeError: Cannot read property 'id' of null
    at eval (index.ts?77fd:9)
    at Object../src/realm/index.ts (renderer.js:5394)
    at __webpack_require__ (renderer.js:791)
    at fn (renderer.js:102)
    at eval (testIndex.tsx?956d:10)
    at Object../testIndex.tsx (renderer.js:5438)
    at __webpack_require__ (renderer.js:791)
    at fn (renderer.js:102)
    at eval (App.tsx?d35d:4)
over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

probably use (add question marks)

useRealmApp?.currentUser?.id

Because if you are not logged in, useRealmApp.currentUser is undefined/null, hence you cannot read .id.

Though, it doesn't seems to be the right way to work with react native, you should probably create a store (redux/useContext), then monitor your user login/logout, and update your user/partition states.

over 4 years ago · Santiago Trujillo Relatório

0

Try this, but not sure if it will work

const user: any = Realm.User;

export const useRealm = Realm.open({
  schema: [ItemSchema],
  sync: {
    user: user.prototype,
    partitionValue: app.currentUser?.id!,
    error: (e) => {
      console.log(e);
    },
  },
});
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda