Hello guys, I am implementing a flutter application which communicates with the cloud appwrite system. On the login step I try to add a push target if this target is missing. The code for this looks like:
Future<void> setUserTarget(String? fcmToken, User user) async {
if (fcmToken != null) {
if (user.targets.isEmpty ||
!user.targets.any((targe) => targe.providerType == 'push')) {
await _account.createPushTarget(
targetId: user.$id,
identifier: fcmToken,
providerId: PROVIDER_ID);
} else {
await _account.updatePushTarget(
targetId: user.$id, identifier: fcmToken);
}
}
}
When I debug through the code I get this state of the user is targest list is empty (see screenshot), but after caling the _account.createPushTarget() function I get the error message: A target with the same ID already exists (see the second screenshot)
I also checked the appwrite console and there is not target for the user.
I am not sure what the problem is. Can anybody help?
Kind regards
How are you getting the user object?
With this line of code: final user = await _account.get();
If you look in console under that user do you see the target for that already?
No, there is no target for that user
is there any reason you're using the users id as the target ID and not ID.Unique()?
Hmm, this is a good point. I was thinking I saw this in the documentation. But, I should use ID.unique()
I will try that
Not that it should be conflicting now since there isn't one, but I'm not sure what it validates for that section off the top of my head.
I looked through the documentation and found this: https://appwrite.io/docs/references/cloud/server-nodejs/users#updateTarget But I mixed it up. I will try with ID.unique and will let you if the problem is solved
I changed my code, now using ID.unique() But I am still facing the same problem
Ok, now something is completely off. I want to try to login with a different user to check if it works or not. Now I get the problem with session_already_exists but nothing is visible in the console
I am not sure what is happening 😰
:( Did you delete the session from your last user?
Recommended threads
- Project restoration button in console
The project restore button in console is taking no effect, i have tried several times and still nothing, it gives same popup if i reload
- SGP region: console returns 401 for all ...
Cloud console cannot open my projects in the Singapore (SGP) region. All console requests return HTTP 401, plus a 503 on analytics.appwrite.io. - Account email...
- Auth not working
guys my appwrite auth isnt working? oauth works (Sign in with google n discord) i have 2 websites deployed where do i get help when i do sign in with email and ...