Apple Developer
I want to send a verification code to the user and the given phone number and check it and create a session right after the user entered the secret. For me that worked out perfect but after that I want to change the users name but everytime I want to run this it gives me the following error: Error: User (role: guests) missing scope (account). Even if the session is created and is listed on the console of Appwrite. Also happens when running account.get()
class Cloud {
var client: Client
var account: Account
var userid = ""
var sessionId: String?
public init() {
self.client = Client()
.setEndpoint("https://cloud.appwrite.io/v1")
.setProject("MY_PROJECT_ID")
self.account = Account(client)
}
func sendCode(number: String) {
Task {
do {
let token = try await account.createPhoneToken(
userId: ID.unique(), // User-ID wird automatisch generiert
phone: number
)
self.userid = token.userId
print("Code wurde gesendet. User-ID: (token.userId)")
} catch {
print("Error1: Failed to send phone token. Error: (error.localizedDescription)")
}
}
}
func verifyAccount(code: String) {
Task {
do {
var session = try await account.createSession(
userId: self.userid,
secret: code
)
_ = client.setSession(session.id)
_ = try await account.updateName(name: "Peter")
self.sessionId = session.id
print("session created successfully: (session.id)") // Ändere $id zu id
} catch {
print("Error2: Failed to verify account. Error: (error.localizedDescription)")
}
}
}
}