@@ -2,20 +2,50 @@ import Foundation
2
2
import Web3Auth
3
3
4
4
class ViewModel : ObservableObject {
5
- var web3Auth : Web3Auth ?
5
+ lazy var web3Auth : Web3Auth ? = nil
6
6
@Published var loggedIn : Bool = false
7
7
@Published var user : Web3AuthState ?
8
8
@Published var isLoading = false
9
9
@Published var navigationTitle : String = " "
10
- private var clientId = " BHr_dKcxC0ecKn_2dZQmQeNdjPgWykMkcodEHkVvPMo71qzOV6SgtoN8KCvFdLN7bf34JOm89vWQMLFmSfIo84A "
11
- private var network : Network = . testnet
10
+ private var clientId = " BPi5PB_UiIZ-cPz1GtV5i1I2iOSOHuimiXBI0e-Oe_u6X3oVAbCiAZOTEBtTXw4tsluTITPqA8zMsfxIKMjiqNQ "
11
+ private var network : Network = . sapphire_mainnet
12
+
12
13
func setup( ) async {
13
14
guard web3Auth == nil else { return }
14
15
await MainActor . run ( body: {
15
16
isLoading = true
16
17
navigationTitle = " Loading "
17
18
} )
18
- web3Auth = await Web3Auth ( . init( clientId: clientId, network: network) )
19
+ web3Auth = await Web3Auth ( W3AInitParams (
20
+ clientId: clientId, network: network,
21
+ loginConfig: [
22
+ TypeOfLogin . google. rawValue:
23
+ . init(
24
+ verifier: " aggregate-sapphire " ,
25
+ typeOfLogin: . google,
26
+ name: " Web3Auth-Aggregate-Verifier-Google-Example " ,
27
+ clientId: " 519228911939-cri01h55lsjbsia1k7ll6qpalrus75ps.apps.googleusercontent.com " ,
28
+ verifierSubIdentifier: " w3a-google "
29
+ )
30
+ ] ,
31
+ whiteLabel: W3AWhiteLabelData (
32
+ appName: " Web3Auth Stub " ,
33
+ logoLight: " https://images.web3auth.io/web3auth-logo-w.svg " ,
34
+ logoDark: " https://images.web3auth.io/web3auth-logo-w.svg " ,
35
+ defaultLanguage: . en, // en, de, ja, ko, zh, es, fr, pt, nl
36
+ mode: . dark,
37
+ theme: [ " primary " : " #d53f8c " ]
38
+ ) ,
39
+ mfaSettings: MfaSettings (
40
+ deviceShareFactor: MfaSetting ( enable: true , priority: 1 ) ,
41
+ backUpShareFactor: MfaSetting ( enable: true , priority: 2 ) ,
42
+ socialBackupFactor: MfaSetting ( enable: true , priority: 3 ) ,
43
+ passwordFactor: MfaSetting ( enable: true , priority: 4 )
44
+ ) ,
45
+ // 259200 allows user to stay authenticated for 3 days with Web3Auth.
46
+ // Default is 86400, which is 1 day.
47
+ sessionTime: 259200
48
+ ) )
19
49
await MainActor . run ( body: {
20
50
if self . web3Auth? . state != nil {
21
51
user = web3Auth? . state
@@ -29,33 +59,7 @@ class ViewModel: ObservableObject {
29
59
func loginWithGoogle( ) {
30
60
Task {
31
61
do {
32
- let result = try await Web3Auth ( . init(
33
- clientId: clientId,
34
- network: network,
35
- loginConfig: [
36
- TypeOfLogin . google. rawValue:
37
- . init(
38
- verifier: " w3a-agg-example " ,
39
- typeOfLogin: . google,
40
- name: " Web3Auth-Aggregate-Verifier-Google-Example " ,
41
- clientId: " 774338308167-q463s7kpvja16l4l0kko3nb925ikds2p.apps.googleusercontent.com " ,
42
- verifierSubIdentifier: " w3a-google "
43
- )
44
- ] ,
45
- whiteLabel: W3AWhiteLabelData (
46
- appName: " Web3Auth Stub " ,
47
- logoLight: " https://images.web3auth.io/web3auth-logo-w.svg " ,
48
- logoDark: " https://images.web3auth.io/web3auth-logo-w.svg " ,
49
- defaultLanguage: . en, // en, de, ja, ko, zh, es, fr, pt, nl
50
- mode: . dark,
51
- theme: [ " primary " : " #d53f8c " ] ) ,
52
- mfaSettings: MfaSettings (
53
- deviceShareFactor: MfaSetting ( enable: true , priority: 1 ) ,
54
- backUpShareFactor: MfaSetting ( enable: true , priority: 2 ) ,
55
- socialBackupFactor: MfaSetting ( enable: true , priority: 3 ) ,
56
- passwordFactor: MfaSetting ( enable: true , priority: 4 )
57
- )
58
- ) ) . login (
62
+ let result = try await web3Auth? . login (
59
63
W3ALoginParams (
60
64
loginProvider: . GOOGLE,
61
65
dappShare: nil ,
@@ -76,20 +80,7 @@ class ViewModel: ObservableObject {
76
80
func loginWithGitHub( ) {
77
81
Task {
78
82
do {
79
- let result = try await Web3Auth ( . init(
80
- clientId: clientId,
81
- network: network,
82
- loginConfig: [
83
- TypeOfLogin . jwt. rawValue:
84
- . init(
85
- verifier: " w3a-agg-example " ,
86
- typeOfLogin: . jwt,
87
- name: " Web3Auth-Aggregate-Verifier-GitHub-Example " ,
88
- clientId: " hiLqaop0amgzCC0AXo4w0rrG9abuJTdu " ,
89
- verifierSubIdentifier: " w3a-a0-github "
90
- )
91
- ]
92
- ) ) . login (
83
+ let result = try await web3Auth? . login (
93
84
W3ALoginParams (
94
85
loginProvider: . JWT,
95
86
dappShare: nil ,
@@ -106,6 +97,13 @@ class ViewModel: ObservableObject {
106
97
}
107
98
}
108
99
}
100
+
101
+ func logout( ) async throws {
102
+ try await web3Auth? . logout ( )
103
+ await MainActor . run ( body: {
104
+ loggedIn = false
105
+ } )
106
+ }
109
107
}
110
108
111
109
extension ViewModel {
0 commit comments