This is probably a silly question, but I have not yet found a good answer.
Is there a method to determine if the current session is anonymous aside from seeing if email, name, etc is blank?
https://appwrite.io/docs/references/cloud/server-nodejs/account#get
This method will throw an error if the user is not logged in.
You can check this error to determine if the user is logged in.
For anonymous users, you can check their roles.
That is what I thought too, but this is not erroring. The images are from a session that was created using createAnonymousSession. account.get is actually succeeding despite the fact that entry was created by the anonymous session.
The error will only occur if the user is not logged in. There should be a field to represent anonymous users; you can try console.log(user) to see the specific name of that field (I forgot because I've forgotten).
https://appwrite.io/docs/references/cloud/models/user https://appwrite.io/docs/references/cloud/models/session
I am not seeing a field that indicates that on either one. Closest I could figure would be provider on the session object. But that doesn't seem to be doing what I thought it would.
Looks like based on the current version of console, they're also determining it by lack of name, email, and phone. So I guess that is the closest thing we have to a deterministic method. https://github.com/appwrite/console/blob/9c8b88e70ff5b7ac6e44130f58839660aab4c48e/src/routes/(console)/project-%5Bregion%5D-%5Bproject%5D/auth/user-%5Buser%5D/dangerZone.svelte#L47
Just check if both phone and the email feild is empty in session object. If yes Annonymous š
Recommended threads
- SMS OTP not delivered to Australian (+61...
Hey team! I'm having an issue with SMS OTP delivery to Australian phone numbers in my Appwrite Cloud project. What's happening: account.createPhoneToken() co...
- OAuth provider credentials reverting [CR...
Hi team, Iām experiencing repeated OAuth configuration resets in my Appwrite project. ## Issue 1 ā Google OAuth credentials reverting * I configure my own Goog...
- updateSession isn't working for google o...
I'm building an app using react native with expo. An image of my code is attached. The code is a useEffect that i have in a context that wraps the root layout ...