Hi,
I'm trying to do oAuth login by google in my Flutter app. And I still have a problem with logging on the application side. After logging in to google, I see in the Appwrite panel that an account and session have been created.
Should I then use the method: account.get() or account.getSession('current') to check if the user is actually logged in? and move to the appropriate screen.
When I use the account.getSession('current') method I get the right data, but when I use account.get() I get error 401 (missing scope).
That's weird...they both should work. account.get()
is more ideal because it's faster (due to caching and not needing to find the matching session)
Hi, I realized that only happens in the mobile version. In the web version, when in the createOAuth2Session method I have the appropriate page passed in the success parameter, everything seems to be ok - logging in and logging out. However, in the mobile version, after logging in, a page appears for a moment with information about the missing of redirect url, but then the get() method returns the appropriate data and I log in the user. On the other hand, the problem seems to occur the next time the get() method is called, before the user logs out. Both the deleteSession(sessionId: 'current') and get methods return me a 401 error as if there is no session created, but there is.
Should I also use success parameter in Flutter for mobile?
sorry what doesn't work in which?
Also, how are you instantiating AppwriteService
and what's the code in that class?
Sorry. Logout doesn't work. in 1st screen I marked result of the getAccoutInfo() method which is basically account.get() method. It's ok. But when I want to logout (2nd screen) I get error 401 from the same previous method. I don' know why. I send You 2 additional screen with AppwriteService class and Main function where I init it.
What were you saying about web vs mobile?
I have the same code for web and mobile. Only difference is using success url for oAuth method in Web version. I don't use it in mobile. In Web everything works fine - login and logout
However, in the mobile version, after logging in, a page appears for a moment with information about the missing of redirect url,
And then the user is redirected into the app automatically?
Yes. It shows for a moment and then is redirected automatically
can you use the dev tools to inspect the network traffic and see what request headers are used in that 2nd account.get() call?
I hope you meant this:)
and this is whole log from the beginning. First login and check session- it's ok. And next accout.get() and delete session - not ok
I think I know where the problem could be. I did the test again. But this time I only cleared the application data, deleted the account and session in the Appwrite panel, but did not clear the data of the Chrome browser on the phone, which had previously saved the login data. Now after logging again, logging out worked as well. It may be related to the fact that the data is stored in the browser?
but you said everything was working fine in web. do you mean stored in the mobile app? If so, yes, the app could be re-using an old session cookie
Yes. In web everything is ok. But problem is still with logout in mobile, but only when I login by google oAuth first time (when google credential are not yet remembered in Chrome). When I try to logout right after login I get an error 401. When I repeat the same action, but with previously remembered credential everything is ok. I can login and right after also logout
your session in chrome shouldn't affect anything...i just tested on android oauth login and then log out worked fine
as long as im logging out in the app.
i do agree that weird things can happen if you delete your session outside of the app
Recommended threads
- Current User is Not authorized
recreating same Thread
- Apple OAuth Scopes
Hi Hi, I've configured sign in with apple and this is the response i'm getting from apple once i've signed in. I cant find anywhere I set scopes. I remember se...
- Sign In With Apple OAuth Help
Hi All! I've got a flutter & appwrite app which Im trying to use sign in with apple for. I already have sign in with google working and the function is the sam...