Skip to content

Commit 12fcca3

Browse files
improve initialization of web3Auth
1 parent 32131f3 commit 12fcca3

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

ios/ios-quick-start/ios-example/ViewModel.swift

+12-9
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,11 @@ class ViewModel: ObservableObject {
2121
isLoading = true
2222
navigationTitle = "Loading"
2323
})
24+
2425
// IMP START - Initialize Web3Auth
25-
web3Auth = await Web3Auth(.init(clientId: clientId, network: network))
26+
web3Auth = await Web3Auth(W3AInitParams(
27+
clientId: clientId, network: network
28+
))
2629
// IMP END - Initialize Web3Auth
2730
await MainActor.run(body: {
2831
if self.web3Auth?.state != nil {
@@ -33,18 +36,20 @@ class ViewModel: ObservableObject {
3336
navigationTitle = loggedIn ? "UserInfo" : "SignIn"
3437
})
3538
}
36-
39+
3740
func login(provider: Web3AuthProvider) {
3841
Task {
3942
do {
4043
// IMP START - Login
41-
let result = try await Web3Auth(.init(clientId: clientId, network: network)).login(W3ALoginParams(loginProvider: provider))
44+
let result = try await web3Auth?.login(
45+
W3ALoginParams(loginProvider: provider)
46+
)
4247
// IMP END - Login
4348
await MainActor.run(body: {
4449
user = result
4550
loggedIn = true
4651
})
47-
52+
4853
} catch {
4954
print("Error")
5055
}
@@ -54,9 +59,7 @@ class ViewModel: ObservableObject {
5459
func logout() throws {
5560
Task {
5661
// IMP START - Logout
57-
try await Web3Auth(.init(
58-
clientId: clientId, network: .sapphire_mainnet
59-
)).logout()
62+
try await web3Auth?.logout()
6063
// IMP END - Logout
6164
await MainActor.run(body: {
6265
loggedIn = false
@@ -68,14 +71,14 @@ class ViewModel: ObservableObject {
6871
Task {
6972
do {
7073
// IMP START - Login
71-
let result = try await Web3Auth(.init(clientId: clientId, network: network)).login(W3ALoginParams(loginProvider: provider, extraLoginOptions: ExtraLoginOptions(display: nil, prompt: nil, max_age: nil, ui_locales: nil, id_token_hint: nil, id_token: nil, login_hint: email, acr_values: nil, scope: nil, audience: nil, connection: nil, domain: nil, client_id: nil, redirect_uri: nil, leeway: nil, verifierIdField: nil, isVerifierIdCaseSensitive: nil, additionalParams: nil)))
74+
let result = try await web3Auth?.login(W3ALoginParams(loginProvider: provider, extraLoginOptions: ExtraLoginOptions(display: nil, prompt: nil, max_age: nil, ui_locales: nil, id_token_hint: nil, id_token: nil, login_hint: email, acr_values: nil, scope: nil, audience: nil, connection: nil, domain: nil, client_id: nil, redirect_uri: nil, leeway: nil, verifierIdField: nil, isVerifierIdCaseSensitive: nil, additionalParams: nil)))
7275
// IMP END - Login
7376
await MainActor.run(body: {
7477
user = result
7578
loggedIn = true
7679
navigationTitle = "UserInfo"
7780
})
78-
81+
7982
} catch {
8083
print("Error")
8184
}

0 commit comments

Comments
 (0)