Skip to content

Commit 0dab27e

Browse files
use shouldUpdateSessionKey in login flow
1 parent 84d1623 commit 0dab27e

File tree

1 file changed

+18
-19
lines changed

1 file changed

+18
-19
lines changed

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,17 @@ 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 {
10+
addSessionKey,
11+
shouldUpdateSessionKey,
12+
} from "thirdweb/extensions/erc4337";
1013
import {
1114
ConnectButton,
1215
ConnectEmbed,
1316
useActiveAccount,
1417
useActiveWallet,
1518
useSiweAuth,
1619
} from "thirdweb/react";
17-
import { isContractDeployed } from "thirdweb/utils";
1820
import { type Account, inAppWallet } from "thirdweb/wallets";
1921
import { createCode } from "../actions/create-code";
2022
import {
@@ -163,31 +165,28 @@ async function ensureSessionKey(options: {
163165
client: options.client,
164166
});
165167

168+
const shouldUpdateSessionkey = await shouldUpdateSessionKey({
169+
account: options.account,
170+
client: options.client,
171+
chain: options.chain,
172+
sessionKeySignerAddress: options.sessionKeySignerAddress,
173+
});
174+
166175
// 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-
}
176+
if (!shouldUpdateSessionkey) {
177+
return {
178+
success: true,
179+
message: "Session key already added",
180+
transaction: null,
181+
};
181182
}
182-
// if not added, send tx to add the session key
183-
183+
// if not added or needs to be updated, send tx to add the session key
184184
const tx = await sendAndConfirmTransaction({
185185
account: options.account,
186186
transaction: addSessionKey({
187187
account: options.account,
188188
contract: accountContract,
189189
sessionKeyAddress: options.sessionKeySignerAddress,
190-
// hard coded for now
191190
permissions: {
192191
approvedTargets:
193192
typeof options.permissions["contracts:write"] === "boolean"

0 commit comments

Comments
 (0)