Skip to content

Commit 822ece4

Browse files
feat: add option to disable storing last passkey credentials (#4944)
1 parent fa826b5 commit 822ece4

File tree

6 files changed

+31
-12
lines changed

6 files changed

+31
-12
lines changed

.changeset/tricky-clouds-swim.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"thirdweb": patch
3+
---
4+
5+
Option to disable storing last stored passkey credentials

packages/thirdweb/src/react/native/ui/connect/InAppWalletUI.tsx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,6 @@ export function PasskeyView(props: InAppWalletFormUIProps) {
393393
<View
394394
style={{
395395
flexDirection: "column",
396-
flex: 1,
397396
alignItems: "center",
398397
justifyContent: "center",
399398
padding: spacing.xl,

packages/thirdweb/src/wallets/in-app/core/authentication/passkeys.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,8 +55,8 @@ export interface PasskeyClient {
5555

5656
export async function registerPasskey(options: {
5757
client: ThirdwebClient;
58-
storage: ClientScopedStorage;
5958
passkeyClient: PasskeyClient;
59+
storage?: ClientScopedStorage;
6060
ecosystem?: Ecosystem;
6161
username?: string;
6262
rp: RpInfo;
@@ -119,17 +119,17 @@ export async function registerPasskey(options: {
119119
);
120120
}
121121
// 4. store the credentialId in local storage
122-
await options.storage.savePasskeyCredentialId(registration.credentialId);
122+
await options.storage?.savePasskeyCredentialId(registration.credentialId);
123123

124124
// 5. returns back the IAW authentication token
125125
return verifData;
126126
}
127127

128128
export async function loginWithPasskey(options: {
129129
client: ThirdwebClient;
130-
storage: ClientScopedStorage;
131130
passkeyClient: PasskeyClient;
132131
rp: RpInfo;
132+
storage?: ClientScopedStorage;
133133
ecosystem?: Ecosystem;
134134
}): Promise<AuthStoredTokenWithCookieReturnType> {
135135
if (!options.passkeyClient.isAvailable()) {
@@ -145,7 +145,8 @@ export async function loginWithPasskey(options: {
145145
const challenge = challengeData.challenge;
146146
// 1.2. find the user's credentialId in local storage
147147
const credentialId =
148-
(await options.storage.getPasskeyCredentialId()) ?? undefined;
148+
(await options.storage?.getPasskeyCredentialId()) ?? undefined;
149+
149150
// 2. initiate login
150151
const authentication = await options.passkeyClient.authenticate({
151152
credentialId,
@@ -188,7 +189,7 @@ export async function loginWithPasskey(options: {
188189
}
189190

190191
// 5. store the credentialId in local storage
191-
await options.storage.savePasskeyCredentialId(authentication.credentialId);
192+
await options.storage?.savePasskeyCredentialId(authentication.credentialId);
192193

193194
// 6. return the auth'd user type
194195
return verifData;

packages/thirdweb/src/wallets/in-app/core/authentication/types.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,12 @@ export type SingleStepAuthArgsType =
4949
* Optional name of the passkey to create, defaults to a generated name
5050
*/
5151
passkeyName?: string;
52+
/**
53+
* Whether to store the last used passkey from local storage.
54+
* This is useful if you want to automatically log in the user with their last used passkey.
55+
* Defaults to true.
56+
*/
57+
storeLastUsedPasskey?: boolean;
5258
}
5359
| {
5460
strategy: "wallet";

packages/thirdweb/src/wallets/in-app/native/native-connector.ts

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -214,10 +214,17 @@ export class InAppNativeConnector implements InAppConnector {
214214
private async passkeyAuth(args: {
215215
type: "sign-up" | "sign-in";
216216
passkeyName?: string;
217+
storeLastUsedPasskey?: boolean;
217218
client: ThirdwebClient;
218219
ecosystem?: Ecosystem;
219220
}): Promise<AuthStoredTokenWithCookieReturnType> {
220-
const { type, passkeyName, client, ecosystem } = args;
221+
const {
222+
type,
223+
passkeyName,
224+
client,
225+
ecosystem,
226+
storeLastUsedPasskey = true,
227+
} = args;
221228
const domain = this.passkeyDomain;
222229
const storage = this.localStorage;
223230
if (!domain) {
@@ -236,7 +243,7 @@ export class InAppNativeConnector implements InAppConnector {
236243
ecosystem,
237244
username: passkeyName,
238245
passkeyClient,
239-
storage,
246+
storage: storeLastUsedPasskey ? storage : undefined,
240247
rp: {
241248
id: domain,
242249
name: domain,
@@ -247,7 +254,7 @@ export class InAppNativeConnector implements InAppConnector {
247254
client,
248255
ecosystem,
249256
passkeyClient,
250-
storage,
257+
storage: storeLastUsedPasskey ? storage : undefined,
251258
rp: {
252259
id: domain,
253260
name: domain,

packages/thirdweb/src/wallets/in-app/web/lib/web-connector.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -411,15 +411,16 @@ export class InAppWebConnector implements InAppConnector {
411411
args: Extract<SingleStepAuthArgsType, { strategy: "passkey" }>,
412412
) {
413413
const { PasskeyWebClient } = await import("./auth/passkeys.js");
414+
const { passkeyName, storeLastUsedPasskey = true } = args;
414415
const passkeyClient = new PasskeyWebClient();
415416
const storage = this.localStorage;
416417
if (args.type === "sign-up") {
417418
return registerPasskey({
418419
client: this.client,
419420
ecosystem: this.ecosystem,
420-
username: args.passkeyName,
421+
username: passkeyName,
421422
passkeyClient,
422-
storage,
423+
storage: storeLastUsedPasskey ? storage : undefined,
423424
rp: {
424425
id: this.passkeyDomain ?? window.location.hostname,
425426
name: this.passkeyDomain ?? window.document.title,
@@ -430,7 +431,7 @@ export class InAppWebConnector implements InAppConnector {
430431
client: this.client,
431432
ecosystem: this.ecosystem,
432433
passkeyClient,
433-
storage,
434+
storage: storeLastUsedPasskey ? storage : undefined,
434435
rp: {
435436
id: this.passkeyDomain ?? window.location.hostname,
436437
name: this.passkeyDomain ?? window.document.title,

0 commit comments

Comments
 (0)