@@ -16,7 +16,10 @@ import { useLogout } from "@/features/authentication/use-logout"
16
16
import { useSmartWalletClient } from "@/features/wallets/smart-wallet"
17
17
import { createXmtpSignerFromSwc } from "@/features/wallets/utils/create-xmtp-signer-from-swc"
18
18
import { createXmtpClient } from "@/features/xmtp/xmtp-client/xmtp-client.service"
19
+ import { validateClientInstallation } from "@/features/xmtp/xmtp-installations/xmtp-installations"
20
+ import { IXmtpInboxId } from "@/features/xmtp/xmtp.types"
19
21
import { captureError , captureErrorWithToast } from "@/utils/capture-error"
22
+ import { IEthereumAddress } from "@/utils/evm/address"
20
23
import { authLogger } from "@/utils/logger"
21
24
import { tryCatch } from "@/utils/try-catch"
22
25
@@ -114,29 +117,31 @@ export const AuthOnboardingContextProvider = (props: IAuthOnboardingContextProps
114
117
authLogger . debug ( `Smart wallet created` )
115
118
116
119
// Step 3: XMTP Inbox client
117
- const signer = createXmtpSignerFromSwc ( swcClient )
118
- const { data : xmtpClient , error : xmtpError } = await tryCatch (
119
- createXmtpClient ( {
120
- inboxSigner : signer ,
121
- } ) ,
122
- )
123
-
124
- if ( xmtpError ) {
125
- throw xmtpError
126
- }
120
+ const xmtpClient = await createXmtpClient ( {
121
+ inboxSigner : createXmtpSignerFromSwc ( swcClient ) ,
122
+ } )
127
123
128
124
if ( ! xmtpClient ) {
129
125
throw new Error ( "XMTP client creation failed" )
130
126
}
131
127
128
+ const isValid = await validateClientInstallation ( {
129
+ client : xmtpClient ,
130
+ } )
131
+
132
+ if ( ! isValid ) {
133
+ throw new Error ( "Invalid client installation" )
134
+ }
135
+
132
136
// Step 4: Set the current sender
133
137
useMultiInboxStore . getState ( ) . actions . setCurrentSender ( {
134
- ethereumAddress : swcClient . account . address ,
135
- inboxId : xmtpClient . inboxId ,
138
+ ethereumAddress : swcClient . account . address as IEthereumAddress ,
139
+ inboxId : xmtpClient . inboxId as IXmtpInboxId ,
136
140
} )
137
141
138
142
await hydrateAuth ( )
139
143
} catch ( error ) {
144
+ useAuthOnboardingStore . getState ( ) . actions . reset ( )
140
145
captureErrorWithToast ( error , {
141
146
message : "Failed to login with passkey" ,
142
147
} )
@@ -194,10 +199,9 @@ export const AuthOnboardingContextProvider = (props: IAuthOnboardingContextProps
194
199
authLogger . debug ( `Smart wallet created` )
195
200
196
201
// Step 3: Create XMTP Inbox
197
- const signer = createXmtpSignerFromSwc ( swcClient )
198
202
const { data : xmtpClient , error : xmtpError } = await tryCatch (
199
203
createXmtpClient ( {
200
- inboxSigner : signer ,
204
+ inboxSigner : createXmtpSignerFromSwc ( swcClient ) ,
201
205
} ) ,
202
206
)
203
207
@@ -211,10 +215,11 @@ export const AuthOnboardingContextProvider = (props: IAuthOnboardingContextProps
211
215
212
216
// Step 4: Set the current sender
213
217
useMultiInboxStore . getState ( ) . actions . setCurrentSender ( {
214
- ethereumAddress : swcClient . account . address ,
215
- inboxId : xmtpClient . inboxId ,
218
+ ethereumAddress : swcClient . account . address as IEthereumAddress ,
219
+ inboxId : xmtpClient . inboxId as IXmtpInboxId ,
216
220
} )
217
221
} catch ( error ) {
222
+ useAuthOnboardingStore . getState ( ) . actions . reset ( )
218
223
captureErrorWithToast ( error , {
219
224
message : "Failed to sign up with passkey" ,
220
225
} )
0 commit comments