Sorry for the bad title. I’ll just go through it step by step:
I just upgraded to dfx 0.12.1 and was using the following lines to make non-anonymous calls from my React frontend but this doesn’t work anymore since createActor
is deprecated:
import { AuthClient } from "@dfinity/auth-client";
import { createActor, canisterId } from '../../declarations/my_project';
const getPrincipal = async () => {
const authClient = await AuthClient.create();
const identity = await authClient.getIdentity();
const myActor = createActor(canisterId, {agentOptions: {identity}});
const response = await myActor.whoami();
setUser(response.toText());
};
The /declarations/my_project_backend/index.js
from where I’m importing createActor
says that we should not import from .dfx but instead use dfx generate
, so I did the following:
- Delete the
declarations
folder from the frontend dfx canister create -all
dfx generate
dfx deploy
Usually I would just call dfx deploy
and all would be good but as soon as I run that, it overwrites /declarations/my_project_backend/index.js
and VisualCode again shows createActor
as deprecated.
The React app also gives a 403 error for a POST request to the backend canister: Body: Failed to authenticate request 0x427c252e5babb46736a6d8f729cfbcbfcb59bd4791ddf7c5a54dc80d63cd4147 due to: Invalid delegation: Invalid canister signature: IcCanisterSignature signature could not be verified
Should I just downgrade dfx? What’s up with the dfx generate
since it does not seem to be run when using dfx deploy
? Any idea how to fix this project?