Impossible to convert undefined to Principal

Hello guys

Error: Impossible to convert undefined to Principal.

Situation: I want to pull logged in user principal ID in the backed. I’m trying to call a backend shared query function after a user is logged in and get this error, if I try to use the backend actor created after login with a new agent.
If i use a normal actor, without a logged in user principal, the call goes fine but I get the anonyms user principal in the backed, which is expected

I’m aware that I’m facing an issue which is already discussed in this forum but the suggestions provided are not helping me or perhaps I’m missing something.

Repo: GitHub - salmanwaseem007/ic_app_new
Front end code: ic_app_new/src/icp_app_new_frontend/src/App.jsx at main · salmanwaseem007/ic_app_new · GitHub
Backend code: ic_app_new/src/icp_app_new_backend/main.mo at main · salmanwaseem007/ic_app_new · GitHub

I have verified the backend canister ID is matching between process.env.CANISTER_ID_ICP_APP_NEW_BACKEND in the chrome and the canister ID itself.

I have also updated by DFX and created a brand new app with it and copied the app code to the new app from old one to the new one without touching anything else.

DFX version: 0.20.0

The error probably comes from the environment handling in your app. Try passing the canisterId as hardcoded:

backendActor = createActor(backend_idl, { agent, canisterId: "bkyz2-fmaaa-aaaaa-qaaaq-cai" });

And one suggestion: just use @ic-reactor/react. You will be impressed by its ease of use and features.

1 Like

still getting the same error. here the the code

I guess you are creating actor in a wrong way!
If you are using the default declarations files that generated using dfx, you should initialize actor like this createActor(canisterId, options = {})

1 Like

it worked. thank you