drewg233Original post
Apple Developer
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:
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:
- Every time I run the app the account.get() fails with the error
User (role: guests) missing scope (account) - 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?
Summary
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.