Skip to content
Back

Trouble with Anonymous Login on iOS

  • 0
  • Apple
drewg233
3 Jul, 2025, 18:49

Ideally I would like to be able to sign in anonymously and persist this user even if they close and reopen the app. Is this possible? Here is what I currently have:

TypeScript
        static func ensureUserSession() async -> Result<User, Error> {
            let account = Account(client)
            do {
                let user = try await account.get()
                return .success(User(id: user.id))
            } catch {
                do {
                    let session = try await account.createAnonymousSession()
                    print(session.userId)
                    return .success(User(id: session.userId))
                } catch {
                    return .failure(error)
                }
            }
        }

My issue is twofold:

  1. Every time I run the app the account.get() fails with the error User (role: guests) missing scope (account)
  2. When it goes to my catch and calls createAnonymousSession() it succeeds, but creates a new user everytime as I can see in my dashboard.

I do have anonymous login enabled in my dashboard. Am I missing something else?

TL;DR
1. User session creation on app launch is failing due to missing scope error. 2. Anonymous session creation successful but results in new user creation each time. Solution: Check if the account has necessary scope for the user role. Make sure anonymous login configuration is correctly set up in the dashboard.
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