Back

Unable to sign-in to Appwrite by following the documentation

  • 0
  • Auth
  • Apple
Stouf
17 Jul, 2024, 14:32

Hello all,

I'm following this documentation https://appwrite.io/docs/quick-starts/apple#step-5

I've created Appwrite.swift file and ContentView.swift fiile with exact same code providing from documentation

ContentView.swift :

TypeScript
import SwiftUI

class ViewModel: ObservableObject {
    @Published var email: String = ""
    @Published var password: String = ""
}

struct ContentView: View {
    @ObservedObject var viewModel = ViewModel()
    
    var body: some View {
        VStack {
            TextField(
                "Email",
                text: $viewModel.email
            )
            SecureField(
                "Password",
                text: $viewModel.password
            )
            Button(
                action: { Task {
                    try await Appwrite.onRegister(
                        viewModel.email,
                        viewModel.password
                    )
                }},
                label: {
                    Text("Register")
                }
            )
            Button(
                action: { Task {
                    try! await Appwrite.onLogin(
                        viewModel.email,
                        viewModel.password
                    )
                }},
                label: {
                    Text("Login")
                }
            )
        }
        .padding()
    }
}

#Preview {
    ContentView()
}
TL;DR
Developers are unable to sign in to Appwrite due to errors related to actor boundaries and the 'Sendable' protocol mismatch. The solution includes creating an instance of the `Appwrite` class and using it to call methods like `onRegister` and `onLogin` instead of accessing them directly. There are issues with the documentation and a SchemeBuildError when previewing the app.
Stouf
17 Jul, 2024, 14:33

Appwrite.swift

TypeScript
import Foundation
import Appwrite
import JSONCodable

class Appwrite {
    var client: Client
    var account: Account
    
    public init() {
        self.client = Client()
            .setEndpoint("https://cloud.appwrite.io/v1")
            .setProject("6672009b002541899792")
            .setSelfSigned(true)
        
        self.account = Account(client)
    }
    
    public func onRegister(
        _ email: String,
        _ password: String
    ) async throws -> User<[String: AnyCodable]> {
        try await account.create(
            userId: ID.unique(),
            email: email,
            password: password
        )
    }
    
    public func onLogin(
        _ email: String,
        _ password: String
    ) async throws -> Session {
        try await account.createEmailPasswordSession(
            email: email,
            password: password
        )
    }
    
    public func onLogout() async throws {
        _ = try await account.deleteSession(
            sessionId: "current"
        )
    }
}

Got the following error inside the ContentView.swift file :

TypeScript
Instance member 'onRegister' cannot be used on type 'Appwrite'; did you mean to use a value of this type instead?
Stouf
17 Jul, 2024, 14:33

And this from the preview :

TypeScript
== DATE:

    Wednesday 17 July 2024 at 16:32:06 Central European Summer Time
    
    2024-07-17T14:32:06Z



== PREVIEW UPDATE ERROR:

    SchemeBuildError: Failed to build the scheme “App
    
    instance member 'onRegister' cannot be used on type 'Appwrite'; did you mean to use a value of this type instead?
    
    Compile ContentView.swift (x86_64):
    /Users/stouf/Workspace/FamilyLove/FamilyLove/FamilyLove/ContentView.swift:30:31: error: instance member 'onRegister' cannot be used on type 'Appwrite'; did you mean to use a value of this type instead?
                        try await Appwrite.onRegister(
                                  ^~~~~~~~
    /Users/stouf/Workspace/FamilyLove/FamilyLove/FamilyLove/ContentView.swift:41:32: error: instance member 'onLogin' cannot be used on type 'Appwrite'; did you mean to use a value of this type instead?
                        try! await Appwrite.onLogin(
                                   ^~~~~~~~
    
```
darShan
17 Jul, 2024, 14:38

Appwrite is a class so maybe try creating an instance of it like -

TypeScript
let appwrite = Appwrite()
appwrite.onLogin(...)

seems like issue with docs, @choir24 (Richard)

Stouf
17 Jul, 2024, 14:40

It is not working as well

darShan
17 Jul, 2024, 14:40

whats the issue?

Stouf
17 Jul, 2024, 14:40
Stouf
17 Jul, 2024, 14:41
TypeScript
Type 'User<[String : AnyCodable]>' does not conform to the 'Sendable' protocol
Stouf
17 Jul, 2024, 14:41
TypeScript
Non-sendable type 'User<[String : AnyCodable]>' returned by implicitly asynchronous call to nonisolated function cannot cross actor boundary
Stouf
17 Jul, 2024, 14:41

Same for onLogin

darShan
17 Jul, 2024, 14:49

I see. atleast the error changed. I am away right now, gonna check this after I come back.

Stouf
17 Jul, 2024, 14:50

thanks a lot !!

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more