Skip to content

Commit 5a4f80d

Browse files
use shouldUpdateSessionKey in login flow
1 parent 84d1623 commit 5a4f80d

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

apps/login/src/components/login-form.tsx

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ import { toast } from "sonner";
66
import { getContract, sendAndConfirmTransaction } from "thirdweb";
77
import type { Chain, ThirdwebClient } from "thirdweb";
88
import { defineChain } from "thirdweb/chains";
9-
import { addSessionKey, isActiveSigner } from "thirdweb/extensions/erc4337";
9+
import { addSessionKey } from "thirdweb/extensions/erc4337";
1010
import {
1111
ConnectButton,
1212
ConnectEmbed,
1313
useActiveAccount,
1414
useActiveWallet,
1515
useSiweAuth,
1616
} from "thirdweb/react";
17-
import { isContractDeployed } from "thirdweb/utils";
1817
import { type Account, inAppWallet } from "thirdweb/wallets";
1918
import { createCode } from "../actions/create-code";
2019
import {
@@ -163,31 +162,28 @@ async function ensureSessionKey(options: {
163162
client: options.client,
164163
});
165164

165+
const shouldUpdateSessionkey = await shouldUpdateSessionKey({
166+
account: options.account,
167+
client: options.client,
168+
chain: options.chain,
169+
sessionKeySignerAddress: options.sessionKeySignerAddress,
170+
});
171+
166172
// check if already added
167-
const accountDeployed = await isContractDeployed(accountContract);
168-
if (accountDeployed) {
169-
if (
170-
await isActiveSigner({
171-
contract: accountContract,
172-
signer: options.sessionKeySignerAddress,
173-
})
174-
) {
175-
return {
176-
success: true,
177-
message: "Session key already added",
178-
transaction: null,
179-
};
180-
}
173+
if (!shouldUpdateSessionkey) {
174+
return {
175+
success: true,
176+
message: "Session key already added",
177+
transaction: null,
178+
};
181179
}
182-
// if not added, send tx to add the session key
183-
180+
// if not added or needs to be updated, send tx to add the session key
184181
const tx = await sendAndConfirmTransaction({
185182
account: options.account,
186183
transaction: addSessionKey({
187184
account: options.account,
188185
contract: accountContract,
189186
sessionKeyAddress: options.sessionKeySignerAddress,
190-
// hard coded for now
191187
permissions: {
192188
approvedTargets:
193189
typeof options.permissions["contracts:write"] === "boolean"

0 commit comments

Comments
 (0)